wc: Make output POSIX compliant

This commit is contained in:
sin 2015-02-06 19:46:37 +00:00
parent 0c8fe5d19b
commit 39802832af
1 changed files with 4 additions and 3 deletions

7
wc.c
View File

@ -17,13 +17,14 @@ void
output(const char *str, size_t nc, size_t nl, size_t nw) output(const char *str, size_t nc, size_t nl, size_t nw)
{ {
int noflags = !cmode && !lflag && !wflag; int noflags = !cmode && !lflag && !wflag;
int first = 1;
if (lflag || noflags) if (lflag || noflags)
printf(" %5zu", nl); printf("%*.zu", first ? (first = 0) : 7, nl);
if (wflag || noflags) if (wflag || noflags)
printf(" %5zu", nw); printf("%*.zu", first ? (first = 0) : 7, nw);
if (cmode || noflags) if (cmode || noflags)
printf(" %5zu", nc); printf("%*.zu", first ? (first = 0) : 7, nc);
if (str) if (str)
printf(" %s", str); printf(" %s", str);
putchar('\n'); putchar('\n');