| 314 | |
| 315 | |
| 316 | static int read_chars (lua_State *L, FILE *f, size_t n) { |
| 317 | size_t rlen; /* how much to read */ |
| 318 | size_t nr; /* number of chars actually read */ |
| 319 | luaL_Buffer b; |
| 320 | luaL_buffinit(L, &b); |
| 321 | rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ |
| 322 | do { |
| 323 | char *p = luaL_prepbuffer(&b); |
| 324 | if (rlen > n) rlen = n; /* cannot read more than asked */ |
| 325 | nr = fread(p, sizeof(char), rlen, f); |
| 326 | luaL_addsize(&b, nr); |
| 327 | n -= nr; /* still have to read `n' chars */ |
| 328 | } while (n > 0 && nr == rlen); /* until end of count or eof */ |
| 329 | luaL_pushresult(&b); /* close buffer */ |
| 330 | return (n == 0 || lua_objlen(L, -1) > 0); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | static int g_read (lua_State *L, FILE *f, int first) { |
no test coverage detected