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