Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/cut From Igor Sobrado in private email (based on his...



details:   https://anonhg.NetBSD.org/src/rev/97372b25946f
branches:  trunk
changeset: 326571:97372b25946f
user:      wiz <wiz%NetBSD.org@localhost>
date:      Mon Feb 03 20:22:19 2014 +0000

description:
>From Igor Sobrado in private email (based on his OpenBSD commit):

    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:

 usr.bin/cut/cut.c |  20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diffs (57 lines):

diff -r 4884d4adb026 -r 97372b25946f usr.bin/cut/cut.c
--- a/usr.bin/cut/cut.c Mon Feb 03 19:18:59 2014 +0000
+++ b/usr.bin/cut/cut.c Mon Feb 03 20:22:19 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cut.c,v 1.28 2012/06/20 17:53:39 wiz Exp $     */
+/*     $NetBSD: cut.c,v 1.29 2014/02/03 20:22:19 wiz Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)cut.c      8.3 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: cut.c,v 1.28 2012/06/20 17:53:39 wiz Exp $");
+__RCSID("$NetBSD: cut.c,v 1.29 2014/02/03 20:22:19 wiz Exp $");
 #endif /* not lint */
 
 #include <ctype.h>
@@ -76,7 +76,7 @@
 {
        FILE *fp;
        void (*fcn)(FILE *, const char *);
-       int ch;
+       int ch, rval;
 
        fcn = NULL;
        (void)setlocale(LC_ALL, "");
@@ -126,20 +126,24 @@
        else if (bflag && cflag)
                usage();
 
+       rval = 0;
        if (*argv)
                for (; *argv; ++argv) {
                        if (strcmp(*argv, "-") == 0)
                                fcn(stdin, "stdin");
                        else {
-                               if ((fp = fopen(*argv, "r")) == NULL)
-                                       err(1, "%s", *argv);
-                               fcn(fp, *argv);
-                               (void)fclose(fp);
+                               if ((fp = fopen(*argv, "r"))) {
+                                       fcn(fp, *argv);
+                                       (void)fclose(fp);
+                               } else {
+                                       rval = 1;
+                                       warn("%s", *argv);
+                               }
                        }
                }
        else
                fcn(stdin, "stdin");
-       return 0;
+       return(rval);
 }
 
 static size_t autostart, autostop, maxval;



Home | Main Index | Thread Index | Old Index