| 482 | |
| 483 | |
| 484 | static 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 | |
| 505 | static void read_all (lua_State *L, FILE *f) { |
no test coverage detected