diff options
Diffstat (limited to 'lzio.c')
-rw-r--r-- | lzio.c | 59 |
1 files changed, 28 insertions, 31 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lzio.c,v 1.6 1999/03/04 14:49:18 roberto Exp roberto $ | 2 | ** $Id: lzio.c,v 1.7 1999/03/05 13:15:50 roberto Exp roberto $ |
3 | ** a generic input stream interface | 3 | ** a generic input stream interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -16,51 +16,48 @@ | |||
16 | /* ----------------------------------------------------- memory buffers --- */ | 16 | /* ----------------------------------------------------- memory buffers --- */ |
17 | 17 | ||
18 | static int zmfilbuf (ZIO* z) { | 18 | static int zmfilbuf (ZIO* z) { |
19 | return EOZ; | 19 | return EOZ; |
20 | } | 20 | } |
21 | 21 | ||
22 | 22 | ||
23 | ZIO* zmopen (ZIO* z, char* b, int size, char *name) | 23 | ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) { |
24 | { | 24 | if (b==NULL) return NULL; |
25 | if (b==NULL) return NULL; | 25 | z->n = size; |
26 | z->n=size; | 26 | z->p = (unsigned const char *)b; |
27 | z->p= (unsigned char *)b; | 27 | z->filbuf = zmfilbuf; |
28 | z->filbuf=zmfilbuf; | 28 | z->u = NULL; |
29 | z->u=NULL; | 29 | z->name = name; |
30 | z->name=name; | 30 | return z; |
31 | return z; | ||
32 | } | 31 | } |
33 | 32 | ||
34 | /* ------------------------------------------------------------ strings --- */ | 33 | /* ------------------------------------------------------------ strings --- */ |
35 | 34 | ||
36 | ZIO* zsopen (ZIO* z, char* s, char *name) | 35 | ZIO* zsopen (ZIO* z, const char* s, const char *name) { |
37 | { | 36 | if (s==NULL) return NULL; |
38 | if (s==NULL) return NULL; | 37 | return zmopen(z,s,strlen(s),name); |
39 | return zmopen(z,s,strlen(s),name); | ||
40 | } | 38 | } |
41 | 39 | ||
42 | /* -------------------------------------------------------------- FILEs --- */ | 40 | /* -------------------------------------------------------------- FILEs --- */ |
43 | 41 | ||
44 | static int zffilbuf (ZIO* z) { | 42 | static int zffilbuf (ZIO* z) { |
45 | int n; | 43 | int n; |
46 | if (feof((FILE *)z->u)) return EOZ; | 44 | if (feof((FILE *)z->u)) return EOZ; |
47 | n=fread(z->buffer,1,ZBSIZE,z->u); | 45 | n = fread(z->buffer,1,ZBSIZE,z->u); |
48 | if (n==0) return EOZ; | 46 | if (n==0) return EOZ; |
49 | z->n=n-1; | 47 | z->n = n-1; |
50 | z->p=z->buffer; | 48 | z->p = z->buffer; |
51 | return *(z->p++); | 49 | return *(z->p++); |
52 | } | 50 | } |
53 | 51 | ||
54 | 52 | ||
55 | ZIO* zFopen (ZIO* z, FILE* f, char *name) | 53 | ZIO* zFopen (ZIO* z, FILE* f, const char *name) { |
56 | { | 54 | if (f==NULL) return NULL; |
57 | if (f==NULL) return NULL; | 55 | z->n = 0; |
58 | z->n=0; | 56 | z->p = z->buffer; |
59 | z->p=z->buffer; | 57 | z->filbuf = zffilbuf; |
60 | z->filbuf=zffilbuf; | 58 | z->u = f; |
61 | z->u=f; | 59 | z->name = name; |
62 | z->name=name; | 60 | return z; |
63 | return z; | ||
64 | } | 61 | } |
65 | 62 | ||
66 | 63 | ||