<read(0)> tests for EOF

This commit is contained in:
Roberto Ierusalimschy
2001-02-09 14:25:50 -02:00
parent 6548bf7462
commit e70e6a3b7a

View File

@@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 1.103 2001/02/02 19:02:40 roberto Exp roberto $
** $Id: liolib.c,v 1.104 2001/02/06 16:01:29 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -272,6 +272,13 @@ static void read_file (lua_State *L, FILE *f) {
static int read_chars (lua_State *L, FILE *f, size_t n) {
if (n == 0) { /* test eof? */
int c = fgetc(f);
ungetc(c, f);
lua_pushlstring(L, NULL, 0);
return (c != EOF);
}
else {
char *buffer;
size_t n1;
char statbuff[LUAL_BUFFERSIZE];
@@ -286,6 +293,7 @@ static int read_chars (lua_State *L, FILE *f, size_t n) {
lua_pushlstring(L, buffer, n1);
if (buffer != statbuff) l_free(buffer, n);
return (n1 > 0 || n == 0);
}
}