Imported from ../lua-3.0.tar.gz.
[lua.git] / src / zio.h
blobf0f36404f06ecaaf943de350edf07306534b3b65
1 /*
2 * zio.h
3 * a generic input stream interface
4 * $Id: zio.h,v 1.5 1997/06/20 19:25:54 roberto Exp $
5 */
7 #ifndef zio_h
8 #define zio_h
10 #include <stdio.h>
14 /* For Lua only */
15 #define zFopen luaZ_Fopen
16 #define zsopen luaZ_sopen
17 #define zmopen luaZ_mopen
18 #define zread luaZ_read
20 #define EOZ (-1) /* end of stream */
22 typedef struct zio ZIO;
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 */
28 int zread(ZIO* z, void* b, int n); /* read next n bytes */
30 #define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
31 #define zungetc(z) (++(z)->n,--(z)->p)
35 /* --------- Private Part ------------------ */
37 #define ZBSIZE 256 /* buffer size */
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 */
48 #endif