ref: db0f050d2b65a5fe329cf9454720420cb2deb721
parent: ebe8f9460b6a3012c9c75d8479a3e427d5c04977
author: aiju <[email protected]>
date: Wed Jul 13 10:17:09 EDT 2011
fixed error handling in p, pr, sed, xd, yacc
--- a/sys/src/cmd/p.c
+++ b/sys/src/cmd/p.c
@@ -21,7 +21,9 @@
fprint(2, "p: can't open /dev/cons\n");
exits("missing /dev/cons");
}
+ Blethal(cons, nil);
Binit(&bout, 1, OWRITE);
+ Blethal(&bout, nil);
n = 0;
while(argc > 1) {
--argc; argv++;
@@ -54,6 +56,7 @@
b = malloc(sizeof(Biobuf));
Binit(b, f, OREAD);
+ Blethal(b, nil);
for(;;){
for(i=1; i <= pglen; i++) {
s = Brdline(b, '\n');
--- a/sys/src/cmd/pr.c
+++ b/sys/src/cmd/pr.c
@@ -147,6 +147,7 @@
int nfdone = 0;
Binit(&bout, 1, OWRITE);
+ Blethal(&bout, nil);
Files = fstr;
for(argc = findopt(argc, argv); argc > 0; --argc, ++argv)
if(Multi == 'm') {
@@ -600,6 +601,7 @@
if(f->f_f == 0)
cerror("no memory");
Binit(f->f_f, 0, OREAD);
+ Blethal(f->f_f, nil);
} else
if((f->f_f = Bopen(f->f_name = s, OREAD)) == 0) {
tmp = ffiler(f->f_name);
@@ -607,6 +609,7 @@
free(tmp);
}
if(f->f_f != 0) {
+ Blethal(f->f_f, nil);
if((f->f_nextc = Bgetrune(f->f_f)) >= 0 || Multi == 'm')
return f->f_f;
sprint(s = (char*)getspace(strlen(f->f_name) + 1 + EMPTY),
--- a/sys/src/cmd/sed.c
+++ b/sys/src/cmd/sed.c
@@ -207,6 +207,7 @@
lnum = 0;
Binit(&fout, 1, OWRITE);
+ Blethal(&fout, nil);
fcode[nfiles++] = &fout;
compfl = 0;
@@ -610,6 +611,7 @@
(fd = create(name, OWRITE, 0666)) < 0)
quit("Cannot create %s", name);
Binit(bp, fd, OWRITE);
+ Blethal(bp, nil);
Bseek(bp, 0, 2);
fcode[nfiles++] = bp;
return bp;
@@ -688,6 +690,7 @@
prog.curr = name;
else if ((prog.bp = Bopen(name, OREAD)) == 0)
quit("Cannot open pattern-file: %s\n", name);
+ Blethal(prog.bp, nil);
prog.type = type;
}
@@ -1347,6 +1350,7 @@
*s = '\0';
if((fi = Bopen(buf, OREAD)) == 0)
continue;
+ Blethal(fi, nil);
while((c = Bgetc(fi)) >= 0)
Bputc(&fout, c);
Bterm(fi);
@@ -1450,6 +1454,7 @@
Binit(&stdin, 0, OREAD);
f = &stdin;
}
+ Blethal(f, nil);
fhead = fhead->next;
return 1;
}
--- a/sys/src/cmd/xd.c
+++ b/sys/src/cmd/xd.c
@@ -65,6 +65,7 @@
Arg *ap;
Binit(&bout, 1, OWRITE);
+ Blethal(&bout, nil);
err = 0;
ap = 0;
while(argc>1 && argv[1][0]=='-' && argv[1][1]){
@@ -205,6 +206,7 @@
bp = &bin;
Binit(bp, fd, OREAD);
}
+ Blethal(bp, nil);
if(title)
xprint("%s\n", name);
addr = 0;
--- a/sys/src/cmd/yacc.c
+++ b/sys/src/cmd/yacc.c
@@ -402,6 +402,7 @@
finput = Bopen(parser, OREAD);
if(finput == 0)
error("cannot find parser %s", parser);
+ Blethal(finput, nil);
warray("yyr1", levprd, nprod);
aryfil(temp1, nprod, 0);
PLOOP(1, i)
@@ -481,6 +482,7 @@
faction = Bopen(actname, OREAD);
if(faction == 0)
error("cannot reopen action tempfile");
+ Blethal(faction, nil);
while((c=Bgetrune(faction)) != Beof)
Bputrune(ftable, c);
Bterm(faction);
@@ -1217,6 +1219,8 @@
faction = Bopen(actname = mktemp(tactname), OWRITE);
if(ftemp == 0 || faction == 0)
error("cannot open temp file");
+ Blethal(ftemp, nil);
+ Blethal(faction, nil);
if(argc < 1)
error("no input file");
infile = argv[0];
@@ -1232,6 +1236,7 @@
finput = Bopen(infile, OREAD);
if(finput == 0)
error("cannot open '%s'", argv[0]);
+ Blethal(finput, nil);
cnamp = cnames;
defin(0, "$end");
@@ -2127,6 +2132,7 @@
foutput = Bopen(buf, OWRITE);
if(foutput == 0)
error("cannot open %s", buf);
+ Blethal(foutput, nil);
}
if(yydebug) {
snprint(buf, sizeof buf, "%s.%s", stem, FILEDEBUG);
@@ -2138,6 +2144,7 @@
fdefine = Bopen(buf, OWRITE);
if(fdefine == 0)
error("can't create %s", buf);
+ Blethal(fdefine, nil);
}
if(ytab == 0)
snprint(buf, sizeof buf, "%s.%s", stem, OFILE);
@@ -2146,6 +2153,7 @@
ftable = Bopen(buf, OWRITE);
if(ftable == 0)
error("cannot open table file %s", buf);
+ Blethal(ftable, nil);
}
/*
@@ -2619,6 +2627,7 @@
finput = Bopen(tempname, OREAD);
if(finput == 0)
error("optimizer cannot open tempfile");
+ Blethal(finput, nil);
pgo[0] = 0;
temp1[0] = 0;