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

Function read_line

deps/lua/src/liolib.c:294–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

292
293
294static int read_line (lua_State *L, FILE *f) {
295 luaL_Buffer b;
296 luaL_buffinit(L, &b);
297 for (;;) {
298 size_t l;
299 char *p = luaL_prepbuffer(&b);
300 if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
301 luaL_pushresult(&b); /* close buffer */
302 return (lua_objlen(L, -1) > 0); /* check whether read something */
303 }
304 l = strlen(p);
305 if (l == 0 || p[l-1] != '\n')
306 luaL_addsize(&b, l);
307 else {
308 luaL_addsize(&b, l - 1); /* do not include `eol' */
309 luaL_pushresult(&b); /* close buffer */
310 return 1; /* read at least an `eol' */
311 }
312 }
313}
314
315
316static int read_chars (lua_State *L, FILE *f, size_t n) {

Callers 2

g_readFunction · 0.85
io_readlineFunction · 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