diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-16 16:25:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-16 16:25:59 -0300 |
commit | d600a6b5b358c28d482b01f10bfa3292b17f5d12 (patch) | |
tree | 8f9047a23315351b32571092cade0883ace6f60e /lzio.h | |
parent | 75ac0d217266dba48a887df96d37398140e22b9e (diff) | |
download | lua-d600a6b5b358c28d482b01f10bfa3292b17f5d12.tar.gz lua-d600a6b5b358c28d482b01f10bfa3292b17f5d12.tar.bz2 lua-d600a6b5b358c28d482b01f10bfa3292b17f5d12.zip |
a generic input stream interface
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 | ||