/* * AUTHOR * N. Nielsen * * LICENSE * This software is in the public domain. * * The software is provided "as is", without warranty of any kind, * express or implied, including but not limited to the warranties * of merchantability, fitness for a particular purpose, and * noninfringement. In no event shall the author(s) be liable for any * claim, damages, or other liability, whether in an action of * contract, tort, or otherwise, arising from, out of, or in connection * with the software or the use or other dealings in the software. * * SUPPORT * Send bug reports to: */ #ifndef __BINFILE_H__ #define __BINFILE_H__ #ifdef __cplusplus extern "C" { #endif #ifdef _WIN32 #pragma pack(push, ops) #endif #pragma pack(1) /* bfval: ---------------------------------------------------------- * A tagged value to be written/read from a binfile */ typedef struct _bfval { short id; /* The tag id */ short type; /* The data type */ size_t len; /* The length in bytes */ } bfval; #pragma pack() #ifdef _WIN32 #pragma pack(pop, ops) #endif /* BFILE: -------------------------------------------------------- * The binfile open handle */ typedef void* BFILE; #define BINTYPE_NONE (short)0x0000 #define BINTYPE_INT16 (short)0x0001 #define BINTYPE_INT32 (short)0x0002 #define BINTYPE_ASCII (short)0x0005 #define BINTYPE_DATA (short)0x0010 #define BINTYPE_END (short)0xFFFF #define BINSIZE_INT32 4 /* sizeof(int) */ #define BINSIZE_INT16 2 /* sizeof(short) */ #define BF_REALLOC 0x00000001 /* Open a binfile based on a disk FILE */ BFILE bfStartFile(FILE* file); /* Open a binfile based on memory */ BFILE bfStartMem(void* mem, size_t len, int flags); /* Write raw data to a binfile at current position */ int bfWriteRaw(BFILE h, const void* data, size_t len); /* Read raw data from a binfile at the current position */ int bfReadRaw(BFILE h, void* data, size_t len); /* Check if an error occured during reading/writing */ int bfError(BFILE h); /* Write a bfval to binfile */ int bfWriteValue(BFILE h, const bfval* opt, const void* data); /* Write a string to a binfile */ int bfWriteString(BFILE h, short id, const char* data); /* Write a 4 byte integer to a binfile */ int bfWriteInt(BFILE h, short id, int data); /* Write the end tag marker */ int bfWriteEnd(BFILE h); /* Read the tag information for a value */ int bfReadValueInfo(BFILE h, bfval* opt); /* Read the data for a value */ int bfReadValueData(BFILE h, const bfval* opt, void* data); /* Skip the data for the current value */ int bfSkipValueData(BFILE h, const bfval* opt); size_t bfCount(BFILE h); void* bfInternal(BFILE h); /* Close a binfile */ void bfClose(BFILE h); #ifdef __cplusplus } #endif #endif /* __BINFILE_H__ */