The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/openzfs/module/lua/lzio.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2 ** $Id: lzio.c,v 1.35.1.1 2013/04/12 18:48:47 roberto Exp $
    3 ** Buffered streams
    4 ** See Copyright Notice in lua.h
    5 */
    6 
    7 
    8 #define lzio_c
    9 #define LUA_CORE
   10 
   11 #include <sys/lua/lua.h>
   12 
   13 #include "llimits.h"
   14 #include "lmem.h"
   15 #include "lstate.h"
   16 #include "lzio.h"
   17 
   18 
   19 int luaZ_fill (ZIO *z) {
   20   size_t size;
   21   lua_State *L = z->L;
   22   const char *buff;
   23   lua_unlock(L);
   24   buff = z->reader(L, z->data, &size);
   25   lua_lock(L);
   26   if (buff == NULL || size == 0)
   27     return EOZ;
   28   z->n = size - 1;  /* discount char being returned */
   29   z->p = buff;
   30   return cast_uchar(*(z->p++));
   31 }
   32 
   33 
   34 void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
   35   z->L = L;
   36   z->reader = reader;
   37   z->data = data;
   38   z->n = 0;
   39   z->p = NULL;
   40 }
   41 
   42 
   43 /* --------------------------------------------------------------- read --- */
   44 size_t luaZ_read (ZIO *z, void *b, size_t n) {
   45   while (n) {
   46     size_t m;
   47     if (z->n == 0) {  /* no bytes in buffer? */
   48       if (luaZ_fill(z) == EOZ)  /* try to read more */
   49         return n;  /* no more input; return number of missing bytes */
   50       else {
   51         z->n++;  /* luaZ_fill consumed first byte; put it back */
   52         z->p--;
   53       }
   54     }
   55     m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */
   56     memcpy(b, z->p, m);
   57     z->n -= m;
   58     z->p += m;
   59     b = (char *)b + m;
   60     n -= m;
   61   }
   62   return 0;
   63 }
   64 
   65 /* ------------------------------------------------------------------------ */
   66 char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
   67   if (n > buff->buffsize) {
   68     if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
   69     luaZ_resizebuffer(L, buff, n);
   70   }
   71   return buff->buffer;
   72 }

Cache object: dd1f53a76f7bfad725d5e61a134a4b2e


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.