| 503 | |
| 504 | |
| 505 | static int read_line (lua_State *L, FILE *f, int chop) { |
| 506 | luaL_Buffer b; |
| 507 | int c; |
| 508 | luaL_buffinit(L, &b); |
| 509 | do { /* may need to read several chunks to get whole line */ |
| 510 | char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */ |
| 511 | int i = 0; |
| 512 | l_lockfile(f); /* no memory errors can happen inside the lock */ |
| 513 | while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') |
| 514 | buff[i++] = c; /* read up to end of line or buffer limit */ |
| 515 | l_unlockfile(f); |
| 516 | luaL_addsize(&b, i); |
| 517 | } while (c != EOF && c != '\n'); /* repeat until end of line */ |
| 518 | if (!chop && c == '\n') /* want a newline and have one? */ |
| 519 | luaL_addchar(&b, c); /* add ending newline to result */ |
| 520 | luaL_pushresult(&b); /* close buffer */ |
| 521 | /* return ok if read something (either a newline or something else) */ |
| 522 | return (c == '\n' || lua_rawlen(L, -1) > 0); |
| 523 | } |
| 524 | |
| 525 | |
| 526 | static void read_all (lua_State *L, FILE *f) { |
no test coverage detected