/* $Id: mbf.h,v 1.1 2008/05/06 20:04:41 ryo Exp $ */ /* * Copyright (c) 2008 SHIMIZU Ryo * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _MBF_H_ #define _MBF_H_ struct mbf { struct mbuf *mbf_m0; /* beginning of mbuf */ struct mbuf *mbf_cur; /* current pointed mbuf */ unsigned int mbf_flags; #define MBFFLAGS_RDONLY 0x00000001 #define MBFFLAGS_WRONLY 0x00000002 #define MBFFLAGS_RDWR (MBFFLAGS_RDONLY|MBFFLAGS_WRONLY) #define MBFFLAGS_MODEMASK MBFFLAGS_RDWR int mbf_size; /* total amount of mbuf chain. 0 is unknown */ int mbf_cur_base; /* offset of mbf_cur in mbuf chain */ int mbf_cur_offset; /* offset of pointer in mbf_cur */ }; void mbf_open(struct mbf *, struct mbuf *, unsigned int); static inline void mbf_close(struct mbf *); static inline int mbf_length(struct mbf *); static inline int mbf_tell(struct mbf *); static inline int mbf_eof(struct mbf *mbf); int mbf_seek(struct mbf *, int, int); #define mbf_rewind(mbf) mbf_seek(mbf, 0, 0) int mbf_read_1(struct mbf *); int mbf_read_2(struct mbf *); uint32_t mbf_read_4(struct mbf *); int mbf_read(struct mbf *, void *, int); void *mbf_getbuf(struct mbf *, void *, int); static inline void mbf_close(struct mbf *mbf __unused) { /* nothing to do */ return; } static inline int mbf_length(struct mbf *mbf) { if (mbf->mbf_size == 0) mbf->mbf_size = m_length(mbf->mbf_m0); return mbf->mbf_size; } static inline int mbf_tell(struct mbf *mbf) { return mbf->mbf_cur_base + mbf->mbf_cur_offset; } static inline int mbf_eof(struct mbf *mbf) { return (mbf->mbf_cur->m_next == NULL) && (mbf->mbf_cur->m_len == mbf->mbf_cur_offset); } /* DEBUG */ void mbf_dump(struct mbf *); #endif /* _MBF_H_ */