diff options
Diffstat (limited to 'zio.h')
-rw-r--r-- | zio.h | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * zio.h | ||
3 | * a generic input stream interface | ||
4 | * $Id: zio.h,v 1.4 1997/06/13 13:49:16 lhf Exp $ | ||
5 | */ | ||
6 | |||
7 | #ifndef zio_h | ||
8 | #define zio_h | ||
9 | |||
10 | #include <stdio.h> | ||
11 | |||
12 | #define EOZ (-1) /* end of stream */ | ||
13 | |||
14 | typedef struct zio ZIO; | ||
15 | |||
16 | int zgetc(ZIO* z); /* get next byte */ | ||
17 | int zungetc(ZIO* z); /* put back last byte read */ | ||
18 | int zread(ZIO* z, void* b, int n); /* read next n bytes */ | ||
19 | int zclose(ZIO* z); /* close stream */ | ||
20 | |||
21 | ZIO* zFopen(ZIO* z, FILE* f); /* open FILEs */ | ||
22 | ZIO* zfopen(ZIO* z, char* s, char* m); /* file by name */ | ||
23 | ZIO* zpopen(ZIO* z, char* s, char* m); /* pipe */ | ||
24 | ZIO* zsopen(ZIO* z, char* s); /* string */ | ||
25 | ZIO* zmopen(ZIO* z, char* b, int size); /* memory */ | ||
26 | |||
27 | #define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) | ||
28 | #define zungetc(z) (++(z)->n,--(z)->p) | ||
29 | #define zclose(z) (*(z)->close)(z) | ||
30 | |||
31 | |||
32 | |||
33 | /* --------- Private Part ------------------ */ | ||
34 | |||
35 | #define ZBSIZE 256 /* buffer size */ | ||
36 | |||
37 | struct zio { | ||
38 | int n; /* bytes still unread */ | ||
39 | unsigned char* p; /* current position in buffer */ | ||
40 | int (*filbuf)(ZIO* z); | ||
41 | int (*close)(ZIO* z); | ||
42 | void* u; /* additional data */ | ||
43 | unsigned char buffer[ZBSIZE]; /* buffer */ | ||
44 | }; | ||
45 | |||
46 | |||
47 | #endif | ||