[PATCH 02/11] line: do not print new line if nothing else was printed

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

 



Earlier the following printed stray new line.

$ printf "" | ./line

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 text-utils/line.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/text-utils/line.c b/text-utils/line.c
index 486e5dd31..ae10809c2 100644
--- a/text-utils/line.c
+++ b/text-utils/line.c
@@ -42,7 +42,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 int main(int argc, char **argv)
 {
 	wint_t c;
-	int opt;
+	int opt, print_nl = 0;
 	int status = EXIT_SUCCESS;
 
 	static const struct option longopts[] = {
@@ -77,8 +77,10 @@ int main(int argc, char **argv)
 		if (c == '\n')
 			break;
 		putwchar(c);
+		print_nl = 1;
 	}
-	putwchar(L'\n');
+	if (print_nl)
+		putwchar(L'\n');
 
 	return status;
 }
-- 
2.13.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux