MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / read_chars

Function read_chars

deps/lua/src/liolib.c:316–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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