MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / read_line

Function read_line

lib/lua/src/liolib.c:522–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520
521
522static int read_line (lua_State *L, FILE *f, int chop) {
523 luaL_Buffer b;
524 int c;
525 luaL_buffinit(L, &b);
526 do { /* may need to read several chunks to get whole line */
527 char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */
528 int i = 0;
529 l_lockfile(f); /* no memory errors can happen inside the lock */
530 while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
531 buff[i++] = c; /* read up to end of line or buffer limit */
532 l_unlockfile(f);
533 luaL_addsize(&b, i);
534 } while (c != EOF && c != '\n'); /* repeat until end of line */
535 if (!chop && c == '\n') /* want a newline and have one? */
536 luaL_addchar(&b, c); /* add ending newline to result */
537 luaL_pushresult(&b); /* close buffer */
538 /* return ok if read something (either a newline or something else) */
539 return (c == '\n' || lua_rawlen(L, -1) > 0);
540}
541
542
543static void read_all (lua_State *L, FILE *f) {

Callers 1

g_readFunction · 0.85

Calls 2

luaL_buffinitFunction · 0.85
luaL_pushresultFunction · 0.85

Tested by

no test coverage detected