diff options
| -rw-r--r-- | liolib.c | 19 |
1 files changed, 10 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.116 2001/06/22 13:49:42 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.117 2001/06/28 14:45:44 roberto Exp roberto $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -263,7 +263,7 @@ static int read_until (lua_State *L, FILE *f, const l_char *p, int pl) { | |||
| 263 | 263 | ||
| 264 | static int read_number (lua_State *L, FILE *f) { | 264 | static int read_number (lua_State *L, FILE *f) { |
| 265 | double d; | 265 | double d; |
| 266 | if (fscanf(f, l_s(LUA_SCAN_NUMBER), &d) == 1) { | 266 | if (fscanf(f, l_s(LUA_NUMBER_SCAN), &d) == 1) { |
| 267 | lua_pushnumber(L, d); | 267 | lua_pushnumber(L, d); |
| 268 | return 1; | 268 | return 1; |
| 269 | } | 269 | } |
| @@ -280,17 +280,18 @@ static int test_eof (lua_State *L, FILE *f) { | |||
| 280 | 280 | ||
| 281 | 281 | ||
| 282 | static int read_chars (lua_State *L, FILE *f, size_t n) { | 282 | static int read_chars (lua_State *L, FILE *f, size_t n) { |
| 283 | size_t rlen; | 283 | size_t rlen; /* how much to read */ |
| 284 | size_t nr; /* number of chars actually read */ | ||
| 284 | luaL_Buffer b; | 285 | luaL_Buffer b; |
| 285 | luaL_buffinit(L, &b); | 286 | luaL_buffinit(L, &b); |
| 286 | rlen = LUAL_BUFFERSIZE; | 287 | rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ |
| 287 | do { | 288 | do { |
| 288 | l_char *p = luaL_prepbuffer(&b); | 289 | l_char *p = luaL_prepbuffer(&b); |
| 289 | if (rlen > n) rlen = n; | 290 | if (rlen > n) rlen = n; /* cannot read more than asked */ |
| 290 | rlen = fread(p, sizeof(l_char), rlen, f); | 291 | nr = fread(p, sizeof(l_char), rlen, f); |
| 291 | luaL_addsize(&b, rlen); | 292 | luaL_addsize(&b, nr); |
| 292 | n -= rlen; | 293 | n -= nr; /* still have to read `n' chars */ |
| 293 | } while (n > 0 && rlen > 0); /* until end of count or eof */ | 294 | } while (n > 0 && nr == rlen); /* until end of count or eof */ |
| 294 | luaL_pushresult(&b); /* close buffer */ | 295 | luaL_pushresult(&b); /* close buffer */ |
| 295 | return (n == 0 || lua_strlen(L, -1) > 0); | 296 | return (n == 0 || lua_strlen(L, -1) > 0); |
| 296 | } | 297 | } |
