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