summaryrefslogtreecommitdiff
path: root/src/lzio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lzio.c')
-rw-r--r--src/lzio.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/lzio.c b/src/lzio.c
index abe086b4..5121ada8 100644
--- a/src/lzio.c
+++ b/src/lzio.c
@@ -1,5 +1,5 @@
/*
-** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp $
+** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp $
** a generic input stream interface
** See Copyright Notice in lua.h
*/
@@ -34,10 +34,12 @@ int luaZ_fill (ZIO *z) {
int luaZ_lookahead (ZIO *z) {
if (z->n == 0) {
- int c = luaZ_fill(z);
- if (c == EOZ) return c;
- z->n++;
- z->p--;
+ if (luaZ_fill(z) == EOZ)
+ return EOZ;
+ else {
+ z->n++; /* luaZ_fill removed first byte; put back it */
+ z->p--;
+ }
}
return char2int(*z->p);
}
@@ -56,14 +58,8 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
size_t luaZ_read (ZIO *z, void *b, size_t n) {
while (n) {
size_t m;
- if (z->n == 0) {
- if (luaZ_fill(z) == EOZ)
- return n; /* return number of missing bytes */
- else {
- ++z->n; /* filbuf removed first byte; put back it */
- --z->p;
- }
- }
+ if (luaZ_lookahead(z) == EOZ)
+ return n; /* return number of missing bytes */
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
memcpy(b, z->p, m);
z->n -= m;