clearer(?) code (also avoids a warning about 'c' being used
without initialization)
This commit is contained in:
8
liolib.c
8
liolib.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: liolib.c,v 2.140 2014/11/02 19:33:33 roberto Exp roberto $
|
** $Id: liolib.c,v 2.141 2014/11/21 12:17:33 roberto Exp roberto $
|
||||||
** Standard I/O (and system) library
|
** Standard I/O (and system) library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -464,9 +464,9 @@ static int test_eof (lua_State *L, FILE *f) {
|
|||||||
|
|
||||||
static int read_line (lua_State *L, FILE *f, int chop) {
|
static int read_line (lua_State *L, FILE *f, int chop) {
|
||||||
luaL_Buffer b;
|
luaL_Buffer b;
|
||||||
int c;
|
int c = '\0';
|
||||||
luaL_buffinit(L, &b);
|
luaL_buffinit(L, &b);
|
||||||
for (;;) {
|
while (c != EOF && c != '\n') { /* repeat until end of line */
|
||||||
char *buff = luaL_prepbuffer(&b); /* pre-allocate buffer */
|
char *buff = luaL_prepbuffer(&b); /* pre-allocate buffer */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
l_lockfile(f); /* no memory errors can happen inside the lock */
|
l_lockfile(f); /* no memory errors can happen inside the lock */
|
||||||
@@ -474,8 +474,6 @@ static int read_line (lua_State *L, FILE *f, int chop) {
|
|||||||
buff[i++] = c;
|
buff[i++] = c;
|
||||||
l_unlockfile(f);
|
l_unlockfile(f);
|
||||||
luaL_addsize(&b, i);
|
luaL_addsize(&b, i);
|
||||||
if (i < LUAL_BUFFERSIZE)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (!chop && c == '\n') /* want a newline and have one? */
|
if (!chop && c == '\n') /* want a newline and have one? */
|
||||||
luaL_addchar(&b, c); /* add ending newline to result */
|
luaL_addchar(&b, c); /* add ending newline to result */
|
||||||
|
|||||||
Reference in New Issue
Block a user