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

Function read_line

lua/liolib.c:299–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

g_readFunction · 0.70
io_readlineFunction · 0.70

Calls 4

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

Tested by

no test coverage detected