Mercurial > hg > toybox
comparison toys/head.c @ 451:f4cc0a2aa440
Add tests for head
This exposed one issue in head.c -- printf was not flushing and
file names could appear after file contents instead of before.
The issue is fixed by calling xflush after xprintf.
author | Timothy Elliott <tle@holymonkey.com> |
---|---|
date | Fri, 10 Feb 2012 21:59:57 -0800 |
parents | 2c47a9c0c619 |
children |
comparison
equal
deleted
inserted
replaced
450:d8ff3b0980cf | 451:f4cc0a2aa440 |
---|---|
33 { | 33 { |
34 int i, len, lines=TT.lines, size=sizeof(toybuf); | 34 int i, len, lines=TT.lines, size=sizeof(toybuf); |
35 | 35 |
36 if (toys.optc > 1) { | 36 if (toys.optc > 1) { |
37 // Print an extra newline for all but the first file | 37 // Print an extra newline for all but the first file |
38 if (TT.file_no++) printf("\n"); | 38 if (TT.file_no++) xprintf("\n"); |
39 xprintf("==> %s <==\n", name); | 39 xprintf("==> %s <==\n", name); |
40 xflush(); | |
40 } | 41 } |
41 | 42 |
42 while (lines) { | 43 while (lines) { |
43 len = read(fd, toybuf, size); | 44 len = read(fd, toybuf, size); |
44 if (len<0) { | 45 if (len<0) { |