1 /* $NetBSD: lzio.c,v 1.3 2015/02/02 14:03:05 lneto Exp $ */
4 ** Id: lzio.c,v 1.36 2014/11/02 19:19:04 roberto Exp
6 ** See Copyright Notice in lua.h
27 int luaZ_fill (ZIO
*z
) {
32 buff
= z
->reader(L
, z
->data
, &size
);
34 if (buff
== NULL
|| size
== 0)
36 z
->n
= size
- 1; /* discount char being returned */
38 return cast_uchar(*(z
->p
++));
42 void luaZ_init (lua_State
*L
, ZIO
*z
, lua_Reader reader
, void *data
) {
51 /* --------------------------------------------------------------- read --- */
52 size_t luaZ_read (ZIO
*z
, void *b
, size_t n
) {
55 if (z
->n
== 0) { /* no bytes in buffer? */
56 if (luaZ_fill(z
) == EOZ
) /* try to read more */
57 return n
; /* no more input; return number of missing bytes */
59 z
->n
++; /* luaZ_fill consumed first byte; put it back */
63 m
= (n
<= z
->n
) ? n
: z
->n
; /* min. between n and z->n */
73 /* ------------------------------------------------------------------------ */
74 char *luaZ_openspace (lua_State
*L
, Mbuffer
*buff
, size_t n
) {
75 if (n
> buff
->buffsize
) {
76 if (n
< LUA_MINBUFFER
) n
= LUA_MINBUFFER
;
77 luaZ_resizebuffer(L
, buff
, n
);