Path: blob/main/sys/contrib/openzfs/module/lua/lzio.h
48383 views
// SPDX-License-Identifier: MIT1/*2** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 roberto Exp $3** Buffered streams4** See Copyright Notice in lua.h5*/678#ifndef lzio_h9#define lzio_h1011#include <sys/lua/lua.h>1213#include "lmem.h"141516#define EOZ (-1) /* end of stream */1718typedef struct Zio ZIO;1920#define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))212223typedef struct Mbuffer {24char *buffer;25size_t n;26size_t buffsize;27} Mbuffer;2829#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)3031#define luaZ_buffer(buff) ((buff)->buffer)32#define luaZ_sizebuffer(buff) ((buff)->buffsize)33#define luaZ_bufflen(buff) ((buff)->n)3435#define luaZ_resetbuffer(buff) ((buff)->n = 0)363738#define luaZ_resizebuffer(L, buff, size) \39(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \40(buff)->buffsize = size)4142#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)434445LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);46LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,47void *data);48LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */49505152/* --------- Private Part ------------------ */5354struct Zio {55size_t n; /* bytes still unread */56const char *p; /* current position in buffer */57lua_Reader reader; /* reader function */58void* data; /* additional data */59lua_State *L; /* Lua state (for reader) */60};616263LUAI_FUNC int luaZ_fill (ZIO *z);6465#endif666768