summaryrefslogtreecommitdiff
path: root/src/lzio.c
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2000-11-06 12:00:00 +0000
committerrepogen <>2000-11-06 12:00:00 +0000
commit8cb71cb5548e3138e5d4e4744f52c79d9fafb116 (patch)
tree25859eb162c67eafc46866e0ec3a9a7ebf93157a /src/lzio.c
parentb7610da5fed99f59ac73ae452da8839a0f2c1bda (diff)
downloadlua-github-4.0.tar.gz
Lua 4.04.0
Diffstat (limited to 'src/lzio.c')
-rw-r--r--src/lzio.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/lzio.c b/src/lzio.c
index 865d9c5e..c958fe46 100644
--- a/src/lzio.c
+++ b/src/lzio.c
@@ -1,5 +1,5 @@
/*
-** $Id: lzio.c,v 1.7 1999/03/05 13:15:50 roberto Exp $
+** $Id: lzio.c,v 1.13 2000/06/12 13:52:05 roberto Exp $
** a generic input stream interface
** See Copyright Notice in lua.h
*/
@@ -9,6 +9,8 @@
#include <stdio.h>
#include <string.h>
+#include "lua.h"
+
#include "lzio.h"
@@ -16,62 +18,60 @@
/* ----------------------------------------------------- memory buffers --- */
static int zmfilbuf (ZIO* z) {
- return EOZ;
+ (void)z; /* to avoid warnings */
+ return EOZ;
}
-ZIO* zmopen (ZIO* z, char* b, int size, char *name)
-{
- if (b==NULL) return NULL;
- z->n=size;
- z->p= (unsigned char *)b;
- z->filbuf=zmfilbuf;
- z->u=NULL;
- z->name=name;
- return z;
+ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name) {
+ if (b==NULL) return NULL;
+ z->n = size;
+ z->p = (const unsigned char *)b;
+ z->filbuf = zmfilbuf;
+ z->u = NULL;
+ z->name = name;
+ return z;
}
/* ------------------------------------------------------------ strings --- */
-ZIO* zsopen (ZIO* z, char* s, char *name)
-{
- if (s==NULL) return NULL;
- return zmopen(z,s,strlen(s),name);
+ZIO* zsopen (ZIO* z, const char* s, const char *name) {
+ if (s==NULL) return NULL;
+ return zmopen(z, s, strlen(s), name);
}
/* -------------------------------------------------------------- FILEs --- */
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;
- return *(z->p++);
+ size_t n;
+ if (feof((FILE *)z->u)) return EOZ;
+ n = fread(z->buffer, 1, ZBSIZE, (FILE *)z->u);
+ if (n==0) return EOZ;
+ z->n = n-1;
+ z->p = z->buffer;
+ return *(z->p++);
}
-ZIO* zFopen (ZIO* z, FILE* f, char *name)
-{
- if (f==NULL) return NULL;
- z->n=0;
- z->p=z->buffer;
- z->filbuf=zffilbuf;
- z->u=f;
- z->name=name;
- return z;
+ZIO* zFopen (ZIO* z, FILE* f, const char *name) {
+ if (f==NULL) return NULL;
+ z->n = 0;
+ z->p = z->buffer;
+ z->filbuf = zffilbuf;
+ z->u = f;
+ z->name = name;
+ return z;
}
/* --------------------------------------------------------------- read --- */
-int zread (ZIO *z, void *b, int n) {
+size_t zread (ZIO *z, void *b, size_t n) {
while (n) {
- int m;
+ size_t m;
if (z->n == 0) {
if (z->filbuf(z) == EOZ)
return n; /* return number of missing bytes */
- zungetc(z); /* put result from 'filbuf' in the buffer */
+ zungetc(z); /* put result from `filbuf' in the buffer */
}
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
memcpy(b, z->p, m);