From 74ff5f42c5ebd35d269c5794a0d51975effffc2e Mon Sep 17 00:00:00 2001 From: tjr Date: Fri, 24 May 2002 10:58:21 +0000 Subject: If a file argument cannot be processed, process the remaining ones and exit non-zero (SUSv3) --- usr.bin/sed/main.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index 2250d5a..de89280 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -96,6 +96,7 @@ static struct s_flist *files, **fl_nextp = &files; int aflag, eflag, nflag; int rflags = 0; +static int rval; /* Exit status */ /* * Current file and line number; line numbers restart across compilation @@ -175,7 +176,7 @@ main(argc, argv) cfclose(prog, NULL); if (fclose(stdout)) err(1, "stdout"); - exit (0); + exit(rval); } static void @@ -318,8 +319,12 @@ mf_fgets(sp, spflag) continue; } fname = files->fname; - if ((f = fopen(fname, "r")) == NULL) - err(1, "%s", fname); + if ((f = fopen(fname, "r")) == NULL) { + warn("%s", fname); + rval = 1; + files = files->next; + continue; + } if (inplace != NULL && *inplace == '\0') unlink(fname); } @@ -350,7 +355,7 @@ mf_fgets(sp, spflag) /* Advance to next non-empty file */ while ((c = getc(f)) == EOF) { (void)fclose(f); - files = files->next; +next: files = files->next; if (files == NULL) { lastline = 1; return (1); @@ -366,8 +371,11 @@ mf_fgets(sp, spflag) continue; } fname = files->fname; - if ((f = fopen(fname, "r")) == NULL) - err(1, "%s", fname); + if ((f = fopen(fname, "r")) == NULL) { + warn("%s", fname); + rval = 1; + goto next; + } if (inplace != NULL && *inplace == '\0') unlink(fname); } -- cgit v1.1