Module Name:    src
Committed By:   ginsbach
Date:           Thu Dec 31 04:07:37 UTC 2020

Modified Files:
        src/usr.bin/nl: nl.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/nl/nl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/nl/nl.c
diff -u src/usr.bin/nl/nl.c:1.14 src/usr.bin/nl/nl.c:1.15
--- src/usr.bin/nl/nl.c:1.14	Wed Dec 30 01:42:31 2020
+++ src/usr.bin/nl/nl.c	Thu Dec 31 04:07:37 2020
@@ -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 @@ filter(void)
 		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");

Reply via email to