| 12203 | |
| 12204 | |
| 12205 | static int read_line (lua_State *L, FILE *f) { |
| 12206 | luaL_Buffer b; |
| 12207 | luaL_buffinit(L, &b); |
| 12208 | for (;;) { |
| 12209 | size_t l; |
| 12210 | char *p = luaL_prepbuffer(&b); |
| 12211 | if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ |
| 12212 | luaL_pushresult(&b); /* close buffer */ |
| 12213 | return (lua_objlen(L, -1) > 0); /* check whether read something */ |
| 12214 | } |
| 12215 | l = strlen(p); |
| 12216 | if (l == 0 || p[l-1] != '\n') |
| 12217 | luaL_addsize(&b, l); |
| 12218 | else { |
| 12219 | luaL_addsize(&b, l - 1); /* do not include `eol' */ |
| 12220 | luaL_pushresult(&b); /* close buffer */ |
| 12221 | return 1; /* read at least an `eol' */ |
| 12222 | } |
| 12223 | } |
| 12224 | } |
| 12225 | |
| 12226 | |
| 12227 | static int read_chars (lua_State *L, FILE *f, size_t n) { |
no test coverage detected