MCPcopy Create free account
hub / github.com/DFHack/dfhack / read_line

Function read_line

depends/lua/src/liolib.c:484–502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

482
483
484static int read_line (lua_State *L, FILE *f, int chop) {
485 luaL_Buffer b;
486 int c = '\0';
487 luaL_buffinit(L, &b);
488 while (c != EOF && c != '\n') { /* repeat until end of line */
489 char *buff = luaL_prepbuffer(&b); /* preallocate buffer */
490 int i = 0;
491 l_lockfile(f); /* no memory errors can happen inside the lock */
492 while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
493 buff[i++] = c;
494 l_unlockfile(f);
495 luaL_addsize(&b, i);
496 }
497 if (!chop && c == '\n') /* want a newline and have one? */
498 luaL_addchar(&b, c); /* add ending newline to result */
499 luaL_pushresult(&b); /* close buffer */
500 /* return ok if read something (either a newline or something else) */
501 return (c == '\n' || lua_rawlen(L, -1) > 0);
502}
503
504
505static void read_all (lua_State *L, FILE *f) {

Callers 1

g_readFunction · 0.85

Calls 3

luaL_buffinitFunction · 0.85
luaL_pushresultFunction · 0.85
lua_rawlenFunction · 0.85

Tested by

no test coverage detected