diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-12-08 23:11:25 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-12-08 23:11:25 +0000 |
commit | fae171e337c39c7bfd46a3c31ce8f2a640ff8e55 (patch) | |
tree | 61fcf151a28a34ac14aa8231a819e98eae3ca31b | |
parent | 72d1eececebe3d4a9764ce6adaafedbc1c30f2ff (diff) |
revert previous, it breaks regress and the llvm, gtk+2, and gtk+3 ports
because it changes the behaviour for empty input files;
revert requested by naddy@ and sthen@
-rw-r--r-- | usr.bin/sed/main.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index 5cffd9a11b9..62644543a43 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.39 2018/12/06 20:16:04 martijn Exp $ */ +/* $OpenBSD: main.c,v 1.40 2018/12/08 23:11:24 schwarze Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -345,13 +345,32 @@ mf_fgets(SPACE *sp, enum e_spflag spflag) size_t len; char *p; int c, fd; - static int firstfile = 1; + static int firstfile; + + if (infile == NULL) { + /* stdin? */ + if (files->fname == NULL) { + if (inplace != NULL) + error(FATAL, "-i may not be used with stdin"); + infile = stdin; + fname = "stdin"; + outfile = stdout; + outfname = "stdout"; + } + + firstfile = 1; + } for (;;) { if (infile != NULL && (c = getc(infile)) != EOF) { (void)ungetc(c, infile); break; } + /* If we are here then either eof or no files are open yet */ + if (infile == stdin) { + sp->len = 0; + return (0); + } finish_file(); if (firstfile == 0) files = files->next; @@ -362,13 +381,6 @@ mf_fgets(SPACE *sp, enum e_spflag spflag) return (0); } fname = files->fname; - if (fname == NULL || strcmp(fname, "-") == 0) { - infile = stdin; - fname = "stdin"; - outfile = stdout; - outfname = "stdout"; - break; - } if (inplace != NULL) { if (lstat(fname, &sb) != 0) error(FATAL, "%s: %s", fname, |