diff options
| -rw-r--r-- | bugs | 4 | ||||
| -rw-r--r-- | ldo.c | 28 |
2 files changed, 22 insertions, 10 deletions
| @@ -133,3 +133,7 @@ Wed Dec 29 16:05:43 EDT 1999 | |||
| 133 | >> return gives wrong line in debug information | 133 | >> return gives wrong line in debug information |
| 134 | (by lhf; since 3.2 [at least]) | 134 | (by lhf; since 3.2 [at least]) |
| 135 | 135 | ||
| 136 | ** ldo.c | ||
| 137 | Thu Dec 30 16:39:33 EDT 1999 | ||
| 138 | >> cannot reopen stdin (for binary mode) | ||
| 139 | (by lhf & roberto; since 3.1) | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.62 1999/12/29 16:31:15 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.63 1999/12/30 18:28:40 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -365,18 +365,26 @@ void luaD_gcIM (lua_State *L, const TObject *o) { | |||
| 365 | int lua_dofile (lua_State *L, const char *filename) { | 365 | int lua_dofile (lua_State *L, const char *filename) { |
| 366 | ZIO z; | 366 | ZIO z; |
| 367 | int status; | 367 | int status; |
| 368 | int c; | ||
| 369 | int bin; | 368 | int bin; |
| 370 | char source[MAXFILENAME]; | 369 | char source[MAXFILENAME]; |
| 371 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); | 370 | FILE *f; |
| 372 | if (f == NULL) | ||
| 373 | return 2; | ||
| 374 | c = fgetc(f); | ||
| 375 | ungetc(c, f); | ||
| 376 | bin = (c == ID_CHUNK); | ||
| 377 | if (bin) | ||
| 378 | f = freopen(filename, "rb", f); /* set binary mode */ | ||
| 379 | luaL_filesource(source, filename, sizeof(source)); | 371 | luaL_filesource(source, filename, sizeof(source)); |
| 372 | if (filename == NULL) { | ||
| 373 | f = stdin; | ||
| 374 | bin = 0; /* cannot handle stdin as a binary file */ | ||
| 375 | } | ||
| 376 | else { | ||
| 377 | int c; | ||
| 378 | f = fopen(filename, "r"); | ||
| 379 | if (f == NULL) return 2; /* unable to open file */ | ||
| 380 | c = fgetc(f); | ||
| 381 | ungetc(c, f); | ||
| 382 | bin = (c == ID_CHUNK); | ||
| 383 | if (bin) { | ||
| 384 | f = freopen(filename, "rb", f); /* set binary mode */ | ||
| 385 | if (f == NULL) return 2; /* unable to reopen file */ | ||
| 386 | } | ||
| 387 | } | ||
| 380 | luaZ_Fopen(&z, f, source); | 388 | luaZ_Fopen(&z, f, source); |
| 381 | status = do_main(L, &z, bin); | 389 | status = do_main(L, &z, bin); |
| 382 | if (f != stdin) | 390 | if (f != stdin) |
