浏览代码

added comment explaining why the 'feof' test when loading a file

Roberto Ierusalimschy 16 年之前
父节点
当前提交
ae9ad6c694
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      lauxlib.c

+ 4 - 1
lauxlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.184 2009/02/27 18:18:19 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.185 2009/03/31 17:25:08 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -496,6 +496,9 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
     *size = 1;
     return "\n";
   }
+  /* 'fread' can return > 0 *and* set the EOF flag. If next call to
+     'getF' calls 'fread', terminal may still wait for user input.
+     The next check avoids this problem. */
   if (feof(lf->f)) return NULL;
   *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
   return (*size > 0) ? lf->buff : NULL;