mirror of https://github.com/rusefi/lua.git
bug: cannot reopen stdin (for binary mode)
This commit is contained in:
parent
aee07c6599
commit
b3aaa048b0
4
bugs
4
bugs
|
@ -133,3 +133,7 @@ Wed Dec 29 16:05:43 EDT 1999
|
||||||
>> return gives wrong line in debug information
|
>> return gives wrong line in debug information
|
||||||
(by lhf; since 3.2 [at least])
|
(by lhf; since 3.2 [at least])
|
||||||
|
|
||||||
|
** ldo.c
|
||||||
|
Thu Dec 30 16:39:33 EDT 1999
|
||||||
|
>> cannot reopen stdin (for binary mode)
|
||||||
|
(by lhf & roberto; since 3.1)
|
||||||
|
|
28
ldo.c
28
ldo.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ldo.c,v 1.62 1999/12/29 16:31:15 roberto Exp roberto $
|
** $Id: ldo.c,v 1.63 1999/12/30 18:28:40 roberto Exp roberto $
|
||||||
** Stack and Call structure of Lua
|
** Stack and Call structure of Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -365,18 +365,26 @@ void luaD_gcIM (lua_State *L, const TObject *o) {
|
||||||
int lua_dofile (lua_State *L, const char *filename) {
|
int lua_dofile (lua_State *L, const char *filename) {
|
||||||
ZIO z;
|
ZIO z;
|
||||||
int status;
|
int status;
|
||||||
int c;
|
|
||||||
int bin;
|
int bin;
|
||||||
char source[MAXFILENAME];
|
char source[MAXFILENAME];
|
||||||
FILE *f = (filename == NULL) ? stdin : fopen(filename, "r");
|
FILE *f;
|
||||||
if (f == NULL)
|
|
||||||
return 2;
|
|
||||||
c = fgetc(f);
|
|
||||||
ungetc(c, f);
|
|
||||||
bin = (c == ID_CHUNK);
|
|
||||||
if (bin)
|
|
||||||
f = freopen(filename, "rb", f); /* set binary mode */
|
|
||||||
luaL_filesource(source, filename, sizeof(source));
|
luaL_filesource(source, filename, sizeof(source));
|
||||||
|
if (filename == NULL) {
|
||||||
|
f = stdin;
|
||||||
|
bin = 0; /* cannot handle stdin as a binary file */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int c;
|
||||||
|
f = fopen(filename, "r");
|
||||||
|
if (f == NULL) return 2; /* unable to open file */
|
||||||
|
c = fgetc(f);
|
||||||
|
ungetc(c, f);
|
||||||
|
bin = (c == ID_CHUNK);
|
||||||
|
if (bin) {
|
||||||
|
f = freopen(filename, "rb", f); /* set binary mode */
|
||||||
|
if (f == NULL) return 2; /* unable to reopen file */
|
||||||
|
}
|
||||||
|
}
|
||||||
luaZ_Fopen(&z, f, source);
|
luaZ_Fopen(&z, f, source);
|
||||||
status = do_main(L, &z, bin);
|
status = do_main(L, &z, bin);
|
||||||
if (f != stdin)
|
if (f != stdin)
|
||||||
|
|
Loading…
Reference in New Issue