1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* 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: <nielsen@memberwebs.com>
*/
#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__ */
|