2 ** $Id: lzio.c,v 1.3 1997/12/22 20:57:18 roberto Exp $
3 ** a generic input stream interface
4 ** See Copyright Notice in lua.h
16 /* ----------------------------------------------------- memory buffers --- */
18 static int zmfilbuf (ZIO
* z
)
23 ZIO
* zmopen (ZIO
* z
, char* b
, int size
, char *name
)
25 if (b
==NULL
) return NULL
;
27 z
->p
= (unsigned char *)b
;
34 /* ------------------------------------------------------------ strings --- */
36 ZIO
* zsopen (ZIO
* z
, char* s
, char *name
)
38 if (s
==NULL
) return NULL
;
39 return zmopen(z
,s
,strlen(s
),name
);
42 /* -------------------------------------------------------------- FILEs --- */
44 static int zffilbuf (ZIO
* z
)
46 int n
=fread(z
->buffer
,1,ZBSIZE
,z
->u
);
54 ZIO
* zFopen (ZIO
* z
, FILE* f
, char *name
)
56 if (f
==NULL
) return NULL
;
66 /* --------------------------------------------------------------- read --- */
67 int zread (ZIO
*z
, void *b
, int n
)
72 if (z
->filbuf(z
) == EOZ
)
73 return n
; /* retorna quantos faltaram ler */
74 zungetc(z
); /* poe o resultado de filbuf no buffer */
76 m
= (n
<= z
->n
) ? n
: z
->n
; /* minimo de n e z->n */