diff options
author | tjr <tjr@FreeBSD.org> | 2002-05-24 10:58:21 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-05-24 10:58:21 +0000 |
commit | 74ff5f42c5ebd35d269c5794a0d51975effffc2e (patch) | |
tree | 7c41c45643d0193cf6f90ec4ebaa1c723562fdaf /usr.bin | |
parent | 2292a0fbefedec1f30c7492f750fe741b83985eb (diff) | |
download | FreeBSD-src-74ff5f42c5ebd35d269c5794a0d51975effffc2e.zip FreeBSD-src-74ff5f42c5ebd35d269c5794a0d51975effffc2e.tar.gz |
If a file argument cannot be processed, process the remaining ones
and exit non-zero (SUSv3)
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/sed/main.c | 20 |
1 files 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); } |