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

17
sed.c
View File

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