aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/head.c
diff options
context:
space:
mode:
authorIlya Kuzmich <ilya.kuzmich@gmail.com>2017-05-28 17:03:26 +0300
committerRob Landley <rob@landley.net>2017-05-28 17:08:19 -0500
commit1abba7db3df9cd4b7e86355504d39a29312ebedb (patch)
treebdddadf4aa573f0d446bdb1a867ea6c271d735ae /toys/posix/head.c
parentcf2e8d08b3e06a7bdf95c30282a976bbf072a168 (diff)
downloadtoybox-1abba7db3df9cd4b7e86355504d39a29312ebedb.tar.gz
teach head -v and -q
Not POSIX, but implemented in coreutils and busybox. Tests use sed to compensate for the stdin naming difference. Signed-off-by: Ilya Kuzmich <ilya.kuzmich@gmail.com>
Diffstat (limited to 'toys/posix/head.c')
-rw-r--r--toys/posix/head.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/toys/posix/head.c b/toys/posix/head.c
index e3d78866..63eb85b0 100644
--- a/toys/posix/head.c
+++ b/toys/posix/head.c
@@ -4,7 +4,7 @@
*
* See http://opengroup.org/onlinepubs/9699919799/utilities/head.html
-USE_HEAD(NEWTOY(head, "?n#<0=10", TOYFLAG_USR|TOYFLAG_BIN))
+USE_HEAD(NEWTOY(head, "?n#<0=10qv", TOYFLAG_USR|TOYFLAG_BIN))
config HEAD
bool "head"
@@ -16,6 +16,8 @@ config HEAD
stdin. Filename "-" is a synonym for stdin.
-n Number of lines to copy
+ -q Never print headers
+ -v Always print headers
*/
#define FOR_head
@@ -30,9 +32,9 @@ static void do_head(int fd, char *name)
{
int i, len, lines=TT.lines, size=sizeof(toybuf);
- if (toys.optc > 1) {
+ if ((toys.optc > 1 && !(toys.optflags & FLAG_q)) || toys.optflags & FLAG_v) {
// Print an extra newline for all but the first file
- if (TT.file_no++) xprintf("\n");
+ if (TT.file_no) xprintf("\n");
xprintf("==> %s <==\n", name);
xflush();
}
@@ -46,6 +48,8 @@ static void do_head(int fd, char *name)
xwrite(1, toybuf, i);
}
+
+ TT.file_no++;
}
void head_main(void)