aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/wc.c
diff options
context:
space:
mode:
Diffstat (limited to 'toys/posix/wc.c')
-rw-r--r--toys/posix/wc.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/toys/posix/wc.c b/toys/posix/wc.c
index 69c5f382..acd0b3a0 100644
--- a/toys/posix/wc.c
+++ b/toys/posix/wc.c
@@ -33,9 +33,13 @@ GLOBALS(
static void show_lengths(unsigned long *lengths, char *name)
{
- int i, space = 7, first = 1;
+ int i, space, first = 1;
+
+ // POSIX says there should never be leading spaces, but accepts that
+ // traditional implementations use 7 spaces, unless only one file
+ // is being counted, when there should be no leading spaces.
+ space = (toys.optc != 1) ? 7 : 0;
- for (i = 0; i<4; i++) if (toys.optflags == (1<<i)) space = 0;
for (i = 0; i<4; i++) {
if (toys.optflags&(1<<i)) {
printf(" %*ld"+first, space, lengths[i]);