diff options
Diffstat (limited to 'lzio.c')
-rw-r--r-- | lzio.c | 22 |
1 files changed, 9 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lzio.c,v 1.29 2004/04/30 20:13:38 roberto Exp roberto $ | 2 | ** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 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 | */ |
@@ -34,10 +34,12 @@ int luaZ_fill (ZIO *z) { | |||
34 | 34 | ||
35 | int luaZ_lookahead (ZIO *z) { | 35 | int luaZ_lookahead (ZIO *z) { |
36 | if (z->n == 0) { | 36 | if (z->n == 0) { |
37 | int c = luaZ_fill(z); | 37 | if (luaZ_fill(z) == EOZ) |
38 | if (c == EOZ) return c; | 38 | return EOZ; |
39 | z->n++; | 39 | else { |
40 | z->p--; | 40 | z->n++; /* luaZ_fill removed first byte; put back it */ |
41 | z->p--; | ||
42 | } | ||
41 | } | 43 | } |
42 | return char2int(*z->p); | 44 | return char2int(*z->p); |
43 | } | 45 | } |
@@ -56,14 +58,8 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { | |||
56 | size_t luaZ_read (ZIO *z, void *b, size_t n) { | 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { |
57 | while (n) { | 59 | while (n) { |
58 | size_t m; | 60 | size_t m; |
59 | if (z->n == 0) { | 61 | if (luaZ_lookahead(z) == EOZ) |
60 | if (luaZ_fill(z) == EOZ) | 62 | return n; /* return number of missing bytes */ |
61 | return n; /* return number of missing bytes */ | ||
62 | else { | ||
63 | ++z->n; /* filbuf removed first byte; put back it */ | ||
64 | --z->p; | ||
65 | } | ||
66 | } | ||
67 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ | 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ |
68 | memcpy(b, z->p, m); | 64 | memcpy(b, z->p, m); |
69 | z->n -= m; | 65 | z->n -= m; |