Lots of binary mode flags.

This commit is contained in:
David Given 2022-07-17 12:58:48 +02:00
parent cb37502a23
commit 5c2f190c29
24 changed files with 42 additions and 42 deletions

View file

@ -93,13 +93,13 @@ int narg;
postin[0] = dup(0); postin[0] = dup(0);
if (pass1) { if (pass1) {
if (useroif) { if (useroif) {
if ((hashin = fopen(oifile, "r")) == NULL) if ((hashin = fopen(oifile, "rb")) == NULL)
fatal("bad ignore/only file: %s",oifile); fatal("bad ignore/only file: %s",oifile);
buildhash(); buildhash();
fclose(hashin); fclose(hashin);
} }
input = stdin; input = stdin;
output = fdopen(scanout[1], "w"); output = fdopen(scanout[1], "wb");
nfiles = argc; nfiles = argc;
setjmp(env); setjmp(env);
while (argc--) while (argc--)
@ -203,9 +203,9 @@ scan(s) char *s;
oifsuf++; oifsuf++;
if (lastc != oifile[oifsuf] ) { if (lastc != oifile[oifsuf] ) {
oifile[oifsuf] = lastc; oifile[oifsuf] = lastc;
if ((hashin = fopen(oifile, "r")) == NULL) { if ((hashin = fopen(oifile, "rb")) == NULL) {
oifile[oifsuf] = 'x'; oifile[oifsuf] = 'x';
if ((hashin = fopen(oifile, "r")) == NULL) if ((hashin = fopen(oifile, "rb")) == NULL)
fatal("cannot open %s",oifile); fatal("cannot open %s",oifile);
} }
buildhash(); buildhash();
@ -215,7 +215,7 @@ scan(s) char *s;
if (s[0]=='-' && s[1]=='\0') if (s[0]=='-' && s[1]=='\0')
input = stdin; input = stdin;
else else
if ((input = fopen(s, "r")) == NULL) if ((input = fopen(s, "rb")) == NULL)
fatal("cannot open %s",s); fatal("cannot open %s",s);
switch (type) { switch (type) {
case 'x': case 'x':

View file

@ -76,19 +76,19 @@ void _opnchn(int reclen, String* fname, String* mode)
{ {
case 'O': case 'O':
case 'o': case 'o':
if ((f = fopen(fname->strval, "w")) == NULL) if ((f = fopen(fname->strval, "wb")) == NULL)
error(28); error(28);
m = OMODE; m = OMODE;
break; break;
case 'I': case 'I':
case 'i': case 'i':
if ((f = fopen(fname->strval, "r")) == NULL) if ((f = fopen(fname->strval, "rb")) == NULL)
error(28); error(28);
m = IMODE; m = IMODE;
break; break;
case 'r': case 'r':
case 'R': case 'R':
if ((f = fopen(fname->strval, "a")) == NULL) if ((f = fopen(fname->strval, "ab")) == NULL)
error(28); error(28);
m = RMODE; m = RMODE;
break; break;

View file

@ -93,12 +93,12 @@ main(argc, argv)
} }
switch (argc) { switch (argc) {
case 1: break; case 1: break;
case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) case 3: if ((output = fopen(argv[2], "wb")) == (FILE *)0)
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
ofile = argv[2]; ofile = argv[2];
ofile_created = 1; ofile_created = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0) case 2: if ((input = fopen(argv[1], "rb")) == (FILE *)0)
fatal("Can't read %s.\n", argv[1]); fatal("Can't read %s.\n", argv[1]);
break; break;
default:fatal("Usage: %s <ack object> <riscos object>.\n", argv[0]); default:fatal("Usage: %s <ack object> <riscos object>.\n", argv[0]);

View file

@ -102,7 +102,7 @@ main(argc, argv)
switch (argc) { switch (argc) {
case 1: rd_fdopen(0); case 1: rd_fdopen(0);
break; break;
case 3: if ((output = fopen(argv[2], "w")) == 0) { case 3: if ((output = fopen(argv[2], "wb")) == 0) {
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
} }
output_file = argv[2]; output_file = argv[2];

View file

@ -141,12 +141,12 @@ main(argc, argv)
} }
switch (argc) { switch (argc) {
case 1: break; case 1: break;
case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) case 3: if ((output = fopen(argv[2], "wb")) == (FILE *)0)
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
output_file = argv[2]; output_file = argv[2];
outputfile_created = 1; outputfile_created = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0) case 2: if ((input = fopen(argv[1], "rb")) == (FILE *)0)
fatal("Can't read %s.\n", argv[1]); fatal("Can't read %s.\n", argv[1]);
break; break;
default:fatal("Usage: %s <as object> <dl object>.\n", argv[0]); default:fatal("Usage: %s <as object> <dl object>.\n", argv[0]);

View file

@ -102,12 +102,12 @@ main(argc, argv)
} }
switch (argc) { switch (argc) {
case 1: break; case 1: break;
case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) case 3: if ((output = fopen(argv[2], "wb")) == (FILE *)0)
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
ofile = argv[2]; ofile = argv[2];
ofile_created = 1; ofile_created = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0) case 2: if ((input = fopen(argv[1], "rb")) == (FILE *)0)
fatal("Can't read %s.\n", argv[1]); fatal("Can't read %s.\n", argv[1]);
break; break;
default:fatal("Usage: %s <as object> <dl object>.\n", argv[0]); default:fatal("Usage: %s <as object> <dl object>.\n", argv[0]);

View file

@ -38,12 +38,12 @@ main(argc, argv)
program= argv[0] ; program= argv[0] ;
switch (argc) { switch (argc) {
case 1: break; case 1: break;
case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) case 3: if ((output = fopen(argv[2], "wb")) == (FILE *)0)
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
output_file = argv[2]; output_file = argv[2];
output_file_created = 1; output_file_created = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0) case 2: if ((input = fopen(argv[1], "rb")) == (FILE *)0)
fatal("Can't read %s.\n", argv[1]); fatal("Can't read %s.\n", argv[1]);
break; break;
default:fatal("Usage: %s <as object> <dl object>.\n", argv[0]); default:fatal("Usage: %s <as object> <dl object>.\n", argv[0]);

View file

@ -36,11 +36,11 @@ main(argc,argv) char **argv; {
fprintf(stderr,"Usage: %s VU-a.out Bleasdale-a.out\n",argv[0]); fprintf(stderr,"Usage: %s VU-a.out Bleasdale-a.out\n",argv[0]);
exit(-1); exit(-1);
} }
if (freopen(argv[1],"r",stdin)==NULL) { if (freopen(argv[1],"rb",stdin)==NULL) {
perror(argv[1]); perror(argv[1]);
exit(-1); exit(-1);
} }
if (freopen(argv[2],"w",stdout)==NULL) { if (freopen(argv[2],"wb",stdout)==NULL) {
perror(argv[2]); perror(argv[2]);
exit(-1); exit(-1);
} }

View file

@ -108,7 +108,7 @@ main(argc, argv)
case 3: if (! wr_open(argv[2])) case 3: if (! wr_open(argv[2]))
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
output_file = argv[2]; output_file = argv[2];
if ((input = fopen(argv[1], "r")) == (FILE *)0) if ((input = fopen(argv[1], "rb")) == (FILE *)0)
fatal("Can't read %s.\n", argv[1]); fatal("Can't read %s.\n", argv[1]);
break; break;
default:fatal("Usage: %s <Mantra object> <ACK object>.\n", argv[0]); default:fatal("Usage: %s <Mantra object> <ACK object>.\n", argv[0]);

View file

@ -107,7 +107,7 @@ main(argc, argv)
argc-- ; argv++ ; argc-- ; argv++ ;
} }
switch (argc) { switch (argc) {
case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) case 3: if ((output = fopen(argv[2], "wb")) == (FILE *)0)
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
output_file = argv[2]; output_file = argv[2];
outputfile_created = 1; outputfile_created = 1;

View file

@ -139,19 +139,19 @@ while true do
end end
end end
local definitionsfp = io.open(args[1], "w") local definitionsfp = io.open(args[1], "wb")
for word, value in pairs(words) do for word, value in pairs(words) do
definitionsfp:write("%token <y_word> OP_", tostring(value), " /* ", word, " */\n") definitionsfp:write("%token <y_word> OP_", tostring(value), " /* ", word, " */\n")
end end
definitionsfp:close() definitionsfp:close()
local tokensfp = io.open(args[2], "w") local tokensfp = io.open(args[2], "wb")
for word, value in pairs(words) do for word, value in pairs(words) do
tokensfp:write("0, OP_", value, ", 0, \"", word, "\",\n") tokensfp:write("0, OP_", value, ", 0, \"", word, "\",\n")
end end
tokensfp:close() tokensfp:close()
local rulesfp = io.open(args[3], "w") local rulesfp = io.open(args[3], "wb")
rulesfp:write("operation\n") rulesfp:write("operation\n")
for index, insn in ipairs(insns) do for index, insn in ipairs(insns) do
if index == 1 then if index == 1 then

View file

@ -86,7 +86,7 @@ main(argc, argv)
switch (argc) { switch (argc) {
case 1: rd_fdopen(0); case 1: rd_fdopen(0);
break; break;
case 3: if ((output = fopen(argv[2], "w")) == NULL) { case 3: if ((output = fopen(argv[2], "wb")) == NULL) {
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
} }
output_file = argv[2]; output_file = argv[2];

View file

@ -88,7 +88,7 @@ main(argc, argv)
argc-- ; argv++ ; argc-- ; argv++ ;
} }
switch (argc) { switch (argc) {
case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) case 3: if ((output = fopen(argv[2], "wb")) == (FILE *)0)
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
output_file = argv[2]; output_file = argv[2];
outputfile_created = 1; outputfile_created = 1;

View file

@ -165,7 +165,7 @@ pass_1(int argc, char **argv)
continue; continue;
} }
#endif #endif
if ((input = fopen(p, "r")) == NULL) if ((input = fopen(p, "rb")) == NULL)
fatal("can't open %s", p); fatal("can't open %s", p);
#ifdef ASLD #ifdef ASLD
if ( if (

View file

@ -141,7 +141,7 @@ static long our_atol(register char *s)
void in_init(char *filename) { void in_init(char *filename) {
if ((emfile=freopen(filename,"r",stdin))==NULL) if ((emfile=freopen(filename,"rb",stdin))==NULL)
error("Can't open %s",filename); error("Can't open %s",filename);
if (get16()!=sp_magic) if (get16()!=sp_magic)
error("Bad format %s",filename); error("Bad format %s",filename);

View file

@ -34,7 +34,7 @@ void out_init(char *filename)
#endif #endif
if (filename == (char *) 0) if (filename == (char *) 0)
codefile = stdout; codefile = stdout;
else if ((codefile = freopen(filename, "w", stdout)) == NULL) else if ((codefile = freopen(filename, "wb", stdout)) == NULL)
error("Can't create %s", filename); error("Can't create %s", filename);
#ifndef NDEBUG #ifndef NDEBUG
} }

View file

@ -56,7 +56,7 @@ int main(int argc, char* const argv[])
switch (c) switch (c)
{ {
case 'C': case 'C':
cfg_dot_file = fopen(optarg, "w"); cfg_dot_file = fopen(optarg, "wb");
if (!cfg_dot_file) if (!cfg_dot_file)
fatal("couldn't open output file '%s': %s", fatal("couldn't open output file '%s': %s",
optarg, strerror(errno)); optarg, strerror(errno));
@ -64,7 +64,7 @@ int main(int argc, char* const argv[])
break; break;
case 'D': case 'D':
dominance_dot_file = fopen(optarg, "w"); dominance_dot_file = fopen(optarg, "wb");
if (!dominance_dot_file) if (!dominance_dot_file)
fatal("couldn't open output file '%s': %s", fatal("couldn't open output file '%s': %s",
optarg, strerror(errno)); optarg, strerror(errno));
@ -98,7 +98,7 @@ int main(int argc, char* const argv[])
if (outputfilename) if (outputfilename)
{ {
outputfile = fopen(outputfilename, "w"); outputfile = fopen(outputfilename, "wb");
if (!outputfile) if (!outputfile)
fatal("couldn't open output '%s': %s", fatal("couldn't open output '%s': %s",
outputfilename, strerror(errno)); outputfilename, strerror(errno));

View file

@ -140,7 +140,7 @@ static long our_atol(char *s) {
void in_init(char *filename) { void in_init(char *filename) {
emfile = stdin; emfile = stdin;
if (filename && (emfile=freopen(filename,"r",stdin))==NULL) if (filename && (emfile=freopen(filename,"rb",stdin))==NULL)
error("Can't open %s",filename); error("Can't open %s",filename);
if (get16()!=sp_magic) if (get16()!=sp_magic)
error("Bad format %s",filename ? filename : "standard-input"); error("Bad format %s",filename ? filename : "standard-input");

View file

@ -39,7 +39,7 @@ void out_init(char *filename) {
if (filename == (char *) 0) if (filename == (char *) 0)
codefile = stdout; codefile = stdout;
else else
if ((codefile=freopen(filename,"w",stdout))==NULL) if ((codefile=freopen(filename,"wb",stdout))==NULL)
error("Can't create %s",filename); error("Can't create %s",filename);
#ifndef NDEBUG #ifndef NDEBUG
} }

View file

@ -13,7 +13,7 @@ char *filename;
#ifndef sys_close #ifndef sys_close
if ( sys_open( filename, OP_WRITE, &codefile)) { if ( sys_open( filename, OP_WRITE, &codefile)) {
#else #else
if ((codefile = fopen(filename, "w")) != NULL) { if ((codefile = fopen(filename, "wb")) != NULL) {
#endif #endif
#ifdef __solaris__ #ifdef __solaris__
fprint(codefile, ".section \".text\"\n"); fprint(codefile, ".section \".text\"\n");

View file

@ -60,7 +60,7 @@ main(argc, argv)
case 3: if (! wr_open(argv[2])) case 3: if (! wr_open(argv[2]))
fatal("Can't write %s.\n", argv[2]); fatal("Can't write %s.\n", argv[2]);
output_file = argv[2]; output_file = argv[2];
if ((input = fopen(argv[1], "r")) == (FILE *)0) if ((input = fopen(argv[1], "rb")) == (FILE *)0)
fatal("Can't read %s.\n", argv[1]); fatal("Can't read %s.\n", argv[1]);
break; break;
default:fatal("Usage: %s <Sun-3 object> <ACK object>.\n", argv[0]); default:fatal("Usage: %s <Sun-3 object> <ACK object>.\n", argv[0]);

View file

@ -39,7 +39,7 @@ main(argc,argv) char **argv; {
s = "a.out"; s = "a.out";
if (argc >= 2) if (argc >= 2)
s = argv[1]; s = argv[1];
if (freopen(s,"r",stdin) == NULL) if (freopen(s,"rb",stdin) == NULL)
fatal("can't open %s",s); fatal("can't open %s",s);
s = "/dev/tty05"; s = "/dev/tty05";
if (argc >= 3) if (argc >= 3)
@ -54,7 +54,7 @@ main(argc,argv) char **argv; {
tty.sg_flags = RAW; tty.sg_flags = RAW;
stty(ttyfd,&tty); stty(ttyfd,&tty);
} else { } else {
freopen(s,"w",stdout); freopen(s,"wb",stdout);
} }
first = 1; osg = 0; first = 1; osg = 0;
/* uid = getuid(); */ /* uid = getuid(); */

View file

@ -48,7 +48,7 @@ PRIVATE void openofile(char *filename)
strcpy(ofilename, filename); strcpy(ofilename, filename);
strcpy(ofiletemp, filename); strcpy(ofiletemp, filename);
strcat(ofiletemp, ".new"); strcat(ofiletemp, ".new");
if ((ofile = fopen(ofiletemp, "w")) == NULL) if ((ofile = fopen(ofiletemp, "wb")) == NULL)
{ {
fprintf(stderr, "Fatal Error: cannot open output file %s\n", ofiletemp); fprintf(stderr, "Fatal Error: cannot open output file %s\n", ofiletemp);
sys_stop(S_EXIT); sys_stop(S_EXIT);
@ -65,12 +65,12 @@ PRIVATE void installofile(void)
register FILE *f1, *f2; register FILE *f1, *f2;
register int c1, c2; register int c1, c2;
fclose(ofile); fclose(ofile);
if ((f1 = fopen(ofiletemp, "r")) == NULL) if ((f1 = fopen(ofiletemp, "rb")) == NULL)
{ {
fprintf(stderr, "Fatal Error: cannont reopen file %s\n", ofiletemp); fprintf(stderr, "Fatal Error: cannont reopen file %s\n", ofiletemp);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
if ((f2 = fopen(ofilename, "r")) == NULL) if ((f2 = fopen(ofilename, "rb")) == NULL)
{ {
fclose(f1); fclose(f1);
RENAME(ofiletemp, ofilename); RENAME(ofiletemp, ofilename);

View file

@ -65,7 +65,7 @@ acquire_malout() {
static char buf[BUFSIZ]; static char buf[BUFSIZ];
if (!malout) { if (!malout) {
malout = freopen("mal.out", "w", stderr); malout = freopen("mal.out", "wb", stderr);
setbuf(malout, buf); setbuf(malout, buf);
} }
} }