sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 9a17de569a49b376068a210073885c97530a79cd
parent 2ee4c13433af0167678c0639e06a7fae9515b3dd
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 13 Jun 2019 13:07:52 -0700

sed: Print better error message when open fails

Diffstat:
Msed.c | 17+++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/sed.c b/sed.c @@ -370,12 +370,17 @@ compile(char *s, int isfile) { FILE *f; - if (!isfile && !*s) /* empty string script */ - return; - - f = isfile ? fopen(s, "r") : fmemopen(s, strlen(s), "r"); - if (!f) - eprintf("fopen/fmemopen:"); + if (isfile) { + f = fopen(s, "r"); + if (!f) + eprintf("fopen %s:", s); + } else { + if (!*s) /* empty string script */ + return; + f = fmemopen(s, strlen(s), "r"); + if (!f) + eprintf("fmemopen:"); + } /* NOTE: get arg functions can't use genbuf */ while (read_line(f, &genbuf) != EOF) {