summaryrefslogtreecommitdiff
path: root/usr.bin/cut/cut.c
diff options
context:
space:
mode:
authorIgor Sobrado <sobrado@cvs.openbsd.org>2014-02-01 23:34:50 +0000
committerIgor Sobrado <sobrado@cvs.openbsd.org>2014-02-01 23:34:50 +0000
commit20353eeaf61efbd2cb6d969a3494f7a3847f1a30 (patch)
tree25851195b17c092bd7b9f9b564823d51c3409dbb /usr.bin/cut/cut.c
parent915d9c7bf3a6e6b8164cf372905fd855294d6f9c (diff)
improve POSIX compliance by continuing to process the remaining file
operands after not finding an input file. from the IEEE Std 1003.1-2008 (``POSIX.1'') rationale: "Unlike other utilities, some historical implementations of cut exit after not finding an input file, rather than continuing to process the remaining file operands. This behavior is prohibited by this volume of POSIX.1-2008, where only the exit status is affected by this problem." joint work with jmc@, who identified the compliance issue, and millert@ ok millert@, jmc@
Diffstat (limited to 'usr.bin/cut/cut.c')
-rw-r--r--usr.bin/cut/cut.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c
index 9590800b93d..57e820a9dec 100644
--- a/usr.bin/cut/cut.c
+++ b/usr.bin/cut/cut.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cut.c,v 1.16 2013/11/23 17:30:29 deraadt Exp $ */
+/* $OpenBSD: cut.c,v 1.17 2014/02/01 23:34:49 sobrado Exp $ */
/* $NetBSD: cut.c,v 1.9 1995/09/02 05:59:23 jtc Exp $ */
/*
@@ -59,7 +59,7 @@ main(int argc, char *argv[])
{
FILE *fp;
void (*fcn)(FILE *, char *);
- int ch;
+ int ch, eval = 0;
setlocale (LC_ALL, "");
@@ -104,14 +104,21 @@ main(int argc, char *argv[])
if (*argv)
for (; *argv; ++argv) {
- if (!(fp = fopen(*argv, "r")))
- err(1, "%s", *argv);
- fcn(fp, *argv);
- (void)fclose(fp);
+ if (strcmp(*argv, "-") == 0)
+ fcn(stdin, "stdin");
+ else {
+ if ((fp = fopen(*argv, "r"))) {
+ fcn(fp, *argv);
+ (void)fclose(fp);
+ } else {
+ eval = 1;
+ warn("%s", *argv);
+ }
+ }
}
else
fcn(stdin, "stdin");
- exit(0);
+ exit(eval);
}
int autostart, autostop, maxval;