aboutsummaryrefslogtreecommitdiff
path: root/zio.h
diff options
context:
space:
mode:
Diffstat (limited to 'zio.h')
-rw-r--r--zio.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/zio.h b/zio.h
new file mode 100644
index 00000000..7f25b0ad
--- /dev/null
+++ b/zio.h
@@ -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
14typedef struct zio ZIO;
15
16int zgetc(ZIO* z); /* get next byte */
17int zungetc(ZIO* z); /* put back last byte read */
18int zread(ZIO* z, void* b, int n); /* read next n bytes */
19int zclose(ZIO* z); /* close stream */
20
21ZIO* zFopen(ZIO* z, FILE* f); /* open FILEs */
22ZIO* zfopen(ZIO* z, char* s, char* m); /* file by name */
23ZIO* zpopen(ZIO* z, char* s, char* m); /* pipe */
24ZIO* zsopen(ZIO* z, char* s); /* string */
25ZIO* 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
37struct 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