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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
#ifndef BH_IO_H
#define BH_IO_H
#include "Common.h"
#define BH_IO_INFO_CB 0x0000
#define BH_IO_INIT_CB 0x0001
#define BH_IO_DESTROY_CB 0x0002
#define BH_IO_OPEN_CB 0x0003
#define BH_IO_CLOSE_CB 0x0004
#define BH_IO_READ_CB 0x0005
#define BH_IO_WRITE_CB 0x0006
#define BH_IO_PEEK_CB 0x0007
#define BH_IO_TELL_CB 0x0008
#define BH_IO_SEEK_CB 0x0009
#define BH_IO_FLUSH_CB 0x000A
#define BH_IO_SIZE_CB 0x000B
#define BH_IO_FLAGS_CB 0x000C
#define BH_IO_CLEAR_CB 0x000D
#define BH_IO_READ 0x0001
#define BH_IO_WRITE 0x0002
#define BH_IO_READWRITE 0x0003
#define BH_IO_APPEND 0x0010
#define BH_IO_TRUNCATE 0x0020
#define BH_IO_CREATE 0x0040
#define BH_IO_EXIST 0x0080
#define BH_IO_SEEK_SET 0x0000
#define BH_IO_SEEK_CUR 0x0001
#define BH_IO_SEEK_END 0x0002
#define BH_IO_FLAG_OK 0x0000
#define BH_IO_FLAG_ERROR 0x0001
#define BH_IO_FLAG_EOF 0x0002
#define BH_IO_FLAG_OPEN 0x0004
#define BH_FILE_CLASSNAME "BH_File"
typedef struct BH_IO BH_IO;
typedef int (*BH_IOCallback)(void *, int ,void *, void *);
/**
* Creates the IO that represents file with the given \a path.
*
* \param path File path
*
* \return On success, returns IO pointer.
* \return On failure, returns NULL pointer.
*/
BH_IO *BH_FileNew(const char *path);
/**
* Creates the IO that buffers access to other \a io.
*
* \param io IO pointer
*
* \return On success, returns IO pointer.
* \return On failure, returns NULL pointer.
*/
BH_IO *BH_BufferNew(BH_IO *io);
/**
* Creates the IO with specified callback \a cb and \a data.
*
* \param cb Callback
* \param data Initialization data
*
* \return On success, returns IO pointer.
* \return On failure, returns NULL pointer.
*/
BH_IO *BH_IONew(BH_IOCallback cb,
void *data);
/**
* Destroys the \a io.
*
* \param io IO pointer
*/
void BH_IOFree(BH_IO *io);
/**
* Returns the \a io classname.
*
* \param io IO pointer
*
* \return On success, returns pointer to constant string.
* \return On failure, returns NULL pointer
*/
const char *BH_IOClassname(BH_IO* io);
/**
* Opens the \a io in specified \a mode of operation.
*
* \param io IO pointer
* \param mode Mode of operation
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOOpen(BH_IO *io,
int mode);
/**
* Closes the \a io.
*
* \param io IO pointer
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOClose(BH_IO *io);
/**
* Reads up to \a size bytes from the \a io into \a buffer.
*
* \param io IO pointer
* \param buffer Buffer pointer
* \param size Buffer size
* \param actual Bytes read (optional)
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IORead(BH_IO *io,
char *buffer,
size_t size,
size_t *actual);
/**
* Writes up to \a size bytes to the \a io from \a buffer.
*
* \param io IO pointer
* \param buffer Buffer pointer
* \param size Buffer size
* \param actual Bytes written (optional)
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOWrite(BH_IO *io,
const char *buffer,
size_t size,
size_t *actual);
/**
* Peeks up to \a size bytes from \a io into \a buffer.
*
* \param io IO pointer
* \param buffer Buffer pointer
* \param size Buffer size
* \param actial Bytes peeked (optional)
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOPeek(BH_IO *io,
char *buffer,
size_t size,
size_t *actual);
/**
* Tells current \a position in the \a io.
*
* \param io IO pointer
* \param position Position
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOTell(BH_IO *io,
int64_t *position);
/**
* Seeks to specified \a position and \a direction in the \a io.
*
* \param io IO pointer
* \param position Position
* \param direction Direction
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOSeek(BH_IO *io,
int64_t position,
int direction);
/**
* Flushes the internal buffers of the \a io.
*
* \param io IO pointer
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOFlush(BH_IO *io);
/**
* Returns total or available size of the \a io.
*
* \param io IO pointer
* \param size Available/total size
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOSize(BH_IO *io,
int64_t *size);
/**
* Returns flags of the \a io.
*
* \param io IO pointer
*
* \return Flags of the IO
*/
int BH_IOFlags(BH_IO *io);
/**
* Clears errors of the \a io.
*
* \param io IO pointer
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_IOClear(BH_IO *io);
#endif /* BH_IO_H */
|