diff options
| author | Brian Somers <brian@FreeBSD.org> | 2004-06-03 22:33:50 +0000 |
|---|---|---|
| committer | Brian Somers <brian@FreeBSD.org> | 2004-06-03 22:33:50 +0000 |
| commit | 7bbdbe148264332d03c34bda64e561e7e82d245f (patch) | |
| tree | 4e6e0ccb3076b812d103c53ee95060d4e6a5a6cc | |
| parent | b2cd42638f92786767e91cc6689bf1a15b4822bc (diff) | |
Notes
| -rw-r--r-- | usr.bin/sed/main.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index 77c89ae9e8cd2..bb5ffece68f77 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -327,15 +327,21 @@ mf_fgets(SPACE *sp, enum e_spflag spflag) } if (infile != NULL) { fclose(infile); - if (*oldfname != '\0' && - rename(fname, oldfname) != 0) { - warn("rename()"); - unlink(tmpfname); - exit(1); + if (*oldfname != '\0') { + if (rename(fname, oldfname) != 0) { + warn("rename()"); + unlink(tmpfname); + exit(1); + } + *oldfname = '\0'; } - if (*tmpfname != '\0') + if (*tmpfname != '\0') { + if (outfile != NULL && outfile != stdout) + fclose(outfile); + outfile = NULL; rename(tmpfname, fname); - *tmpfname = *oldfname = '\0'; + *tmpfname = '\0'; + } outfname = NULL; } if (firstfile == 0) |
