More binary flags; and, remember to truncate existing files when trying

to create new ones.
This commit is contained in:
David Given 2022-07-17 20:11:21 +02:00
parent 2558d00d17
commit acd2fe1351
3 changed files with 8 additions and 4 deletions

View file

@ -45,7 +45,7 @@ sys_open(path, flag, filep)
} }
/* Fall through */ /* Fall through */
case OP_WRITE: 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; return 0;
break; break;
default: default:

View file

@ -119,7 +119,7 @@ static int run_exec(trf* phase)
oldstdout = dup(1); oldstdout = dup(1);
close(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); close(1);
dup(2); dup(2);
@ -139,7 +139,7 @@ static int run_exec(trf* phase)
if (oldstdout != -1) if (oldstdout != -1)
{ {
int i = close(1); close(1);
dup2(oldstdout, 1); dup2(oldstdout, 1);
close(oldstdout); close(oldstdout);
} }

View file

@ -60,6 +60,7 @@ void fileinit(void)
else else
{ {
outfile = stdout; outfile = stdout;
freopen(NULL, "wb", stdout);
outshort(sp_magic); outshort(sp_magic);
} }
} }
@ -84,8 +85,11 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (argc) if (argc)
if (freopen(*argv, "r", stdin) == NULL) if (freopen(*argv, "rb", stdin) == NULL)
error("Cannot open %s", *argv); error("Cannot open %s", *argv);
else
freopen(NULL, "rb", stdin);
fileinit(); fileinit();
#ifdef USEMALLOC #ifdef USEMALLOC
coreinit(); coreinit();