MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / read_chars

Function read_chars

lua/liolib.c:321–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319
320
321static int read_chars (lua_State *L, FILE *f, size_t n) {
322 size_t rlen; /* how much to read */
323 size_t nr; /* number of chars actually read */
324 luaL_Buffer b;
325 luaL_buffinit(L, &b);
326 rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
327 do {
328 char *p = luaL_prepbuffer(&b);
329 if (rlen > n) rlen = n; /* cannot read more than asked */
330 nr = fread(p, sizeof(char), rlen, f);
331 luaL_addsize(&b, nr);
332 n -= nr; /* still have to read `n' chars */
333 } while (n > 0 && nr == rlen); /* until end of count or eof */
334 luaL_pushresult(&b); /* close buffer */
335 return (n == 0 || lua_objlen(L, -1) > 0);
336}
337
338
339static int g_read (lua_State *L, FILE *f, int first) {

Callers 1

g_readFunction · 0.85

Calls 4

luaL_buffinitFunction · 0.85
luaL_prepbufferFunction · 0.85
luaL_pushresultFunction · 0.85
lua_objlenFunction · 0.85

Tested by

no test coverage detected