Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/nl nl: fix -d delim parsing for POSIX



details:   https://anonhg.NetBSD.org/src/rev/035bd8089fe3
branches:  trunk
changeset: 948731:035bd8089fe3
user:      ginsbach <ginsbach%NetBSD.org@localhost>
date:      Wed Dec 30 01:42:31 2020 +0000

description:
nl: fix -d delim parsing for POSIX

POSIX specifies it is possible to specify a one delimiter character.
Fix the logic so that both one and two character delimiters are accepted.

diffstat:

 usr.bin/nl/nl.c |  19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diffs (41 lines):

diff -r 46de4bfe3307 -r 035bd8089fe3 usr.bin/nl/nl.c
--- a/usr.bin/nl/nl.c   Wed Dec 30 01:33:30 2020 +0000
+++ b/usr.bin/nl/nl.c   Wed Dec 30 01:42:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nl.c,v 1.13 2020/12/22 17:50:55 ginsbach Exp $ */
+/*     $NetBSD: nl.c,v 1.14 2020/12/30 01:42:31 ginsbach Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: nl.c,v 1.13 2020/12/22 17:50:55 ginsbach Exp $");
+__RCSID("$NetBSD: nl.c,v 1.14 2020/12/30 01:42:31 ginsbach Exp $");
 #endif    
 
 #include <errno.h>
@@ -157,14 +157,15 @@
                case 'd':
                        if (optarg[0] != '\0')
                                delim[0] = optarg[0];
-                       if (optarg[1] != '\0')
+                       if (optarg[1] != '\0') {
                                delim[1] = optarg[1];
-                       /* at most two delimiter characters */
-                       if (optarg[2] != '\0') {
-                               errx(EXIT_FAILURE,
-                                   "invalid delim argument -- %s",
-                                   optarg);
-                               /* NOTREACHED */
+                               /* at most two delimiter characters */
+                               if (optarg[2] != '\0') {
+                                       errx(EXIT_FAILURE,
+                                           "invalid delim argument -- %s",
+                                           optarg);
+                                       /* NOTREACHED */
+                               }
                        }
                        break;
                case 'f':



Home | Main Index | Thread Index | Old Index