sed: Print better error message when open fails

This commit is contained in:
Michael Forney 2019-06-13 13:07:52 -07:00
parent 2ee4c13433
commit 9a17de569a
1 changed files with 11 additions and 6 deletions

17
sed.c
View File

@ -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) {