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
|
#ifndef BH_IO_H
#define BH_IO_H
#include "Common.h"
#define BH_IO_OP_DESTROY 0x0000
#define BH_IO_OP_READ 0x0001
#define BH_IO_OP_WRITE 0x0002
#define BH_IO_OP_CTL 0x0003
#define BH_IO_OP_CAP 0x0004
#define BH_IO_CTL_FLAGS 0x0000
#define BH_IO_CTL_CLEAR 0x0001
#define BH_IO_CTL_PEEK 0x0002
#define BH_IO_CTL_FLUSH 0x0003
#define BH_IO_CTL_SIZE 0x0004
#define BH_IO_CTL_TELL 0x0005
#define BH_IO_CTL_SEEK 0x0006
#define BH_IO_CTL_GET_IO 0x0007
#define BH_IO_CTL_SET_IO 0x0008
#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_FILE_READ 0x0001
#define BH_FILE_WRITE 0x0002
#define BH_FILE_READWRITE 0x0003
#define BH_FILE_APPEND 0x0010
#define BH_FILE_TRUNCATE 0x0020
#define BH_FILE_CREATE 0x0040
#define BH_FILE_EXIST 0x0080
typedef int (*BH_IOCallback)(void *, int, void *);
typedef struct BH_IO
{
BH_IOCallback callback;
} BH_IO;
typedef struct BH_IOReadInfo
{
char *data;
size_t size;
size_t *actual;
} BH_IOReadInfo;
typedef struct BH_IOWriteInfo
{
const char *data;
size_t size;
size_t *actual;
} BH_IOWriteInfo;
typedef struct BH_IOCtlInfo
{
int op;
void *arg;
} BH_IOCtlInfo;
typedef struct BH_IOSeekInfo
{
int64_t offset;
int whence;
} BH_IOSeekInfo;
BH_IO *BH_FileNew(const char *path,
int mode,
int *result);
int BH_IOIsFile(BH_IO *device);
BH_IO *BH_BufferNew(BH_IO *device,
size_t size,
int *result);
int BH_IOIsBuffer(BH_IO *device);
BH_IO *BH_BytesNew(char *data,
size_t size,
int *result);
int BH_IOIsBytes(BH_IO *device);
void BH_IOFree(BH_IO *device);
int BH_IORead(BH_IO *device,
char *buffer,
size_t size,
size_t *actual);
int BH_IOWrite(BH_IO *io,
const char *buffer,
size_t size,
size_t *actual);
int BH_IOCtl(BH_IO *device,
int op,
void *arg);
int BH_IOCap(BH_IO *device,
int op);
int BH_IOPeek(BH_IO *device,
char *buffer,
size_t size,
size_t *actual);
int BH_IOTell(BH_IO *device,
int64_t *offset);
int BH_IOSeek(BH_IO *device,
int64_t offset,
int whence);
int BH_IOFlush(BH_IO *device);
int BH_IOSize(BH_IO *device,
int64_t *size);
int BH_IOFlags(BH_IO *device,
int *flags);
int BH_IOError(BH_IO *device);
int BH_IOEndOfFile(BH_IO *device);
int BH_IOClear(BH_IO *device);
char *BH_IOReadLine(BH_IO *device,
char *str,
size_t size);
char *BH_IOReadLineFull(BH_IO *device,
char *str,
size_t size);
#endif /* BH_IO_H */
|