Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/nl PR/55891 supress displaying separator when number...



details:   https://anonhg.NetBSD.org/src/rev/46f40e7b20bd
branches:  trunk
changeset: 979516:46f40e7b20bd
user:      ginsbach <ginsbach%NetBSD.org@localhost>
date:      Thu Dec 31 04:07:37 2020 +0000

description:
PR/55891 supress displaying separator when numbers supressed

Fix based on patch provided by Kobayashi Takashi. This brings nl(1) further
in to POSIX compliance. Verified behavior with classic SysV nl(1) and GNU
nl(1). There could still be edge cases here not specified by POSIX.

diffstat:

 usr.bin/nl/nl.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (36 lines):

diff -r 21206068ffcd -r 46f40e7b20bd usr.bin/nl/nl.c
--- a/usr.bin/nl/nl.c   Thu Dec 31 03:49:36 2020 +0000
+++ b/usr.bin/nl/nl.c   Thu Dec 31 04:07:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nl.c,v 1.14 2020/12/30 01:42:31 ginsbach Exp $ */
+/*     $NetBSD: nl.c,v 1.15 2020/12/31 04:07:37 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.14 2020/12/30 01:42:31 ginsbach Exp $");
+__RCSID("$NetBSD: nl.c,v 1.15 2020/12/31 04:07:37 ginsbach Exp $");
 #endif    
 
 #include <errno.h>
@@ -332,13 +332,13 @@
                if (donumber) {
                        consumed = snprintf(intbuffer, intbuffersize, format,
                            width, line);
-                       (void)printf("%s",
-                           intbuffer + max(0, consumed - width));
+                       (void)printf("%s%s",
+                           intbuffer + max(0, consumed - width), sep);
                        line += incr;
                } else {
-                       (void)printf("%*s", width, "");
+                       (void)printf("%*s%*s", width, "", (int)strlen(sep), "");
                }
-               (void)printf("%s%s", sep, buffer);
+               (void)printf("%s", buffer);
 
                if (ferror(stdout))
                        err(EXIT_FAILURE, "output error");



Home | Main Index | Thread Index | Old Index