aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--liolib.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/liolib.c b/liolib.c
index afefc1ec..fddbf0cc 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.114 2013/06/07 19:01:35 roberto Exp roberto $ 2** $Id: liolib.c,v 2.115 2014/01/27 13:28:45 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*/
@@ -403,20 +403,15 @@ static int read_line (lua_State *L, FILE *f, int chop) {
403} 403}
404 404
405 405
406#define MAX_SIZE_T (~(size_t)0)
407
408static void read_all (lua_State *L, FILE *f) { 406static void read_all (lua_State *L, FILE *f) {
409 size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */ 407 size_t nr;
410 luaL_Buffer b; 408 luaL_Buffer b;
411 luaL_buffinit(L, &b); 409 luaL_buffinit(L, &b);
412 for (;;) { 410 do { /* read file in chunks of LUAL_BUFFERSIZE bytes */
413 char *p = luaL_prepbuffsize(&b, rlen); 411 char *p = luaL_prepbuffsize(&b, LUAL_BUFFERSIZE);
414 size_t nr = fread(p, sizeof(char), rlen, f); 412 nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);
415 luaL_addsize(&b, nr); 413 luaL_addsize(&b, nr);
416 if (nr < rlen) break; /* eof? */ 414 } while (nr == LUAL_BUFFERSIZE);
417 else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */
418 rlen *= 2; /* double buffer size at each iteration */
419 }
420 luaL_pushresult(&b); /* close buffer */ 415 luaL_pushresult(&b); /* close buffer */
421} 416}
422 417