1 /*
2 ** $Id: lzio.h,v 1.1 2001/10/29 17:49:53 rr9 Exp $
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, const char *name);	/* open FILEs */
26 ZIO* zsopen (ZIO* z, const char* s, const char *name);	/* string */
27 ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name); /* memory */
28 
29 size_t zread (ZIO* z, void* b, size_t 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 #define zname(z)	((z)->name)
34 
35 
36 
37 /* --------- Private Part ------------------ */
38 
39 #ifndef ZBSIZE
40 #define ZBSIZE	256			/* buffer size */
41 #endif
42 
43 struct zio {
44   size_t n;				/* bytes still unread */
45   const unsigned char* p;		/* current position in buffer */
46   int (*filbuf)(ZIO* z);
47   void* u;				/* additional data */
48   const char *name;
49   unsigned char buffer[ZBSIZE];		/* buffer */
50 };
51 
52 
53 #endif
54