diff options
Diffstat (limited to 'lzio.h')
-rw-r--r-- | lzio.h | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | ** $Id: $ | ||
3 | ** Buffered streams | ||
4 | ** See Copyright Notice in lua.h | ||
5 | */ | ||
6 | |||
7 | |||
8 | #ifndef lzio_h | ||
9 | #define lzio_h | ||
10 | |||
11 | #include <stdio.h> | ||
12 | |||
13 | |||
14 | |||
15 | /* For Lua only */ | ||
16 | #define zFopen luaZ_Fopen | ||
17 | #define zsopen luaZ_sopen | ||
18 | #define zmopen luaZ_mopen | ||
19 | #define zread luaZ_read | ||
20 | |||
21 | #define EOZ (-1) /* end of stream */ | ||
22 | |||
23 | typedef struct zio ZIO; | ||
24 | |||
25 | ZIO* zFopen(ZIO* z, FILE* f); /* open FILEs */ | ||
26 | ZIO* zsopen(ZIO* z, char* s); /* string */ | ||
27 | ZIO* zmopen(ZIO* z, char* b, int size); /* memory */ | ||
28 | |||
29 | int zread(ZIO* z, void* b, int n); /* read next n bytes */ | ||
30 | |||
31 | #define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) | ||
32 | #define zungetc(z) (++(z)->n,--(z)->p) | ||
33 | |||
34 | |||
35 | |||
36 | /* --------- Private Part ------------------ */ | ||
37 | |||
38 | #define ZBSIZE 256 /* buffer size */ | ||
39 | |||
40 | struct zio { | ||
41 | int n; /* bytes still unread */ | ||
42 | unsigned char* p; /* current position in buffer */ | ||
43 | int (*filbuf)(ZIO* z); | ||
44 | void* u; /* additional data */ | ||
45 | unsigned char buffer[ZBSIZE]; /* buffer */ | ||
46 | }; | ||
47 | |||
48 | |||
49 | #endif | ||