diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-04-02 16:54:06 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-04-02 16:54:06 -0300 |
commit | ae9ad6c69403252adf05410b89d0353ed774e7e2 (patch) | |
tree | 891e2133887c89ea79dc1b90677607473286a515 | |
parent | 83d2dbb15d22550e88f86e1d51d69945fd52c136 (diff) | |
download | lua-ae9ad6c69403252adf05410b89d0353ed774e7e2.tar.gz lua-ae9ad6c69403252adf05410b89d0353ed774e7e2.tar.bz2 lua-ae9ad6c69403252adf05410b89d0353ed774e7e2.zip |
added comment explaining why the 'feof' test when loading a file
-rw-r--r-- | lauxlib.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.184 2009/02/27 18:18:19 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.185 2009/03/31 17:25:08 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -496,6 +496,9 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { | |||
496 | *size = 1; | 496 | *size = 1; |
497 | return "\n"; | 497 | return "\n"; |
498 | } | 498 | } |
499 | /* 'fread' can return > 0 *and* set the EOF flag. If next call to | ||
500 | 'getF' calls 'fread', terminal may still wait for user input. | ||
501 | The next check avoids this problem. */ | ||
499 | if (feof(lf->f)) return NULL; | 502 | if (feof(lf->f)) return NULL; |
500 | *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); | 503 | *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); |
501 | return (*size > 0) ? lf->buff : NULL; | 504 | return (*size > 0) ? lf->buff : NULL; |