aboutsummaryrefslogtreecommitdiff
path: root/lzio.h
diff options
context:
space:
mode:
Diffstat (limited to 'lzio.h')
-rw-r--r--lzio.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/lzio.h b/lzio.h
new file mode 100644
index 00000000..31ce948e
--- /dev/null
+++ b/lzio.h
@@ -0,0 +1,49 @@
1/*
2** $Id: $
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
23typedef struct zio ZIO;
24
25ZIO* zFopen(ZIO* z, FILE* f); /* open FILEs */
26ZIO* zsopen(ZIO* z, char* s); /* string */
27ZIO* zmopen(ZIO* z, char* b, int size); /* memory */
28
29int zread(ZIO* z, void* b, int 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
34
35
36/* --------- Private Part ------------------ */
37
38#define ZBSIZE 256 /* buffer size */
39
40struct zio {
41 int n; /* bytes still unread */
42 unsigned char* p; /* current position in buffer */
43 int (*filbuf)(ZIO* z);
44 void* u; /* additional data */
45 unsigned char buffer[ZBSIZE]; /* buffer */
46};
47
48
49#endif