From fae171e337c39c7bfd46a3c31ce8f2a640ff8e55 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 8 Dec 2018 23:11:25 +0000 Subject: 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@ --- usr.bin/sed/main.c | 30 +++++++++++++++++++++--------- 1 file 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, -- cgit v1.2.3