More binary flags; and, remember to truncate existing files when trying
to create new ones.
This commit is contained in:
parent
2558d00d17
commit
acd2fe1351
|
@ -45,7 +45,7 @@ sys_open(path, flag, filep)
|
|||
}
|
||||
/* Fall through */
|
||||
case OP_WRITE:
|
||||
if ((fd = open(path, O_CREAT|O_WRONLY|O_BINARY, 0666)) < 0)
|
||||
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666)) < 0)
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -119,7 +119,7 @@ static int run_exec(trf* phase)
|
|||
|
||||
oldstdout = dup(1);
|
||||
close(1);
|
||||
if (open(out.p_path, O_CREAT|O_WRONLY|O_BINARY, 0666) != 1)
|
||||
if (open(out.p_path, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666) != 1)
|
||||
{
|
||||
close(1);
|
||||
dup(2);
|
||||
|
@ -139,7 +139,7 @@ static int run_exec(trf* phase)
|
|||
|
||||
if (oldstdout != -1)
|
||||
{
|
||||
int i = close(1);
|
||||
close(1);
|
||||
dup2(oldstdout, 1);
|
||||
close(oldstdout);
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ void fileinit(void)
|
|||
else
|
||||
{
|
||||
outfile = stdout;
|
||||
freopen(NULL, "wb", stdout);
|
||||
outshort(sp_magic);
|
||||
}
|
||||
}
|
||||
|
@ -84,8 +85,11 @@ int main(int argc, char* argv[])
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (argc)
|
||||
if (freopen(*argv, "r", stdin) == NULL)
|
||||
if (freopen(*argv, "rb", stdin) == NULL)
|
||||
error("Cannot open %s", *argv);
|
||||
else
|
||||
freopen(NULL, "rb", stdin);
|
||||
|
||||
fileinit();
|
||||
#ifdef USEMALLOC
|
||||
coreinit();
|
||||
|
|
Loading…
Reference in a new issue