1 /* $NetBSD: lzio.c,v 1.1.1.2 2012/03/15 00:08:14 alnsn Exp $ */
4 ** $Id: lzio.c,v 1.1.1.2 2012/03/15 00:08:14 alnsn Exp $
5 ** a generic input stream interface
6 ** See Copyright Notice in lua.h
23 int luaZ_fill (ZIO
*z
) {
28 buff
= z
->reader(L
, z
->data
, &size
);
30 if (buff
== NULL
|| size
== 0) return EOZ
;
33 return char2int(*(z
->p
++));
37 int luaZ_lookahead (ZIO
*z
) {
39 if (luaZ_fill(z
) == EOZ
)
42 z
->n
++; /* luaZ_fill removed first byte; put back it */
46 return char2int(*z
->p
);
50 void luaZ_init (lua_State
*L
, ZIO
*z
, lua_Reader reader
, void *data
) {
59 /* --------------------------------------------------------------- read --- */
60 size_t luaZ_read (ZIO
*z
, void *b
, size_t n
) {
63 if (luaZ_lookahead(z
) == EOZ
)
64 return n
; /* return number of missing bytes */
65 m
= (n
<= z
->n
) ? n
: z
->n
; /* min. between n and z->n */
75 /* ------------------------------------------------------------------------ */
76 char *luaZ_openspace (lua_State
*L
, Mbuffer
*buff
, size_t n
) {
77 if (n
> buff
->buffsize
) {
78 if (n
< LUA_MINBUFFER
) n
= LUA_MINBUFFER
;
79 luaZ_resizebuffer(L
, buff
, n
);