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, 11 insertions, 11 deletions
diff --git a/src/lzio.c b/src/lzio.c
index 0ab1adf4..865d9c5e 100644
--- a/src/lzio.c
+++ b/src/lzio.c
@@ -1,5 +1,5 @@
/*
-** $Id: lzio.c,v 1.3 1997/12/22 20:57:18 roberto Exp $
+** $Id: lzio.c,v 1.7 1999/03/05 13:15:50 roberto Exp $
** a generic input stream interface
** See Copyright Notice in lua.h
*/
@@ -15,11 +15,11 @@
/* ----------------------------------------------------- memory buffers --- */
-static int zmfilbuf (ZIO* z)
-{
+static int zmfilbuf (ZIO* z) {
return EOZ;
}
+
ZIO* zmopen (ZIO* z, char* b, int size, char *name)
{
if (b==NULL) return NULL;
@@ -41,9 +41,10 @@ ZIO* zsopen (ZIO* z, char* s, char *name)
/* -------------------------------------------------------------- FILEs --- */
-static int zffilbuf (ZIO* z)
-{
- int n=fread(z->buffer,1,ZBSIZE,z->u);
+static int zffilbuf (ZIO* z) {
+ int n;
+ if (feof((FILE *)z->u)) return EOZ;
+ n=fread(z->buffer,1,ZBSIZE,z->u);
if (n==0) return EOZ;
z->n=n-1;
z->p=z->buffer;
@@ -64,16 +65,15 @@ ZIO* zFopen (ZIO* z, FILE* f, char *name)
/* --------------------------------------------------------------- read --- */
-int zread (ZIO *z, void *b, int n)
-{
+int zread (ZIO *z, void *b, int n) {
while (n) {
int m;
if (z->n == 0) {
if (z->filbuf(z) == EOZ)
- return n; /* retorna quantos faltaram ler */
- zungetc(z); /* poe o resultado de filbuf no buffer */
+ return n; /* return number of missing bytes */
+ zungetc(z); /* put result from 'filbuf' in the buffer */
}
- m = (n <= z->n) ? n : z->n; /* minimo de n e z->n */
+ m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
memcpy(b, z->p, m);
z->n -= m;
z->p += m;