# HG changeset patch # User Rob Landley # Date 1328791002 21600 # Node ID 2c47a9c0c619b05ad3bfa384ffaafa95c6856906 # Parent d3ca5e15e4572a94e1cddc3a7b872a9cbb7ef1b7 Cleanups for head. diff -r d3ca5e15e457 -r 2c47a9c0c619 toys/head.c --- a/toys/head.c Mon Feb 06 17:35:59 2012 -0800 +++ b/toys/head.c Thu Feb 09 06:36:42 2012 -0600 @@ -6,13 +6,14 @@ * * See http://www.opengroup.org/onlinepubs/009695399/utilities/head.html -USE_HEAD(NEWTOY(head, "n#", TOYFLAG_BIN)) +USE_HEAD(NEWTOY(head, "n#<0=10", TOYFLAG_BIN)) config HEAD bool "head" default y help usage: head [-n number] [file...] + Copy first lines from files to stdout. If no files listed, copy from stdin. Filename "-" is a synonym for stdin. @@ -34,11 +35,11 @@ if (toys.optc > 1) { // Print an extra newline for all but the first file - if (TT.file_no++ > 0) printf("\n"); - printf("==> %s <==\n", name); + if (TT.file_no++) printf("\n"); + xprintf("==> %s <==\n", name); } - for (;lines>0;) { + while (lines) { len = read(fd, toybuf, size); if (len<0) { perror_msg("%s",name); @@ -46,17 +47,14 @@ } if (len<1) break; - for(i=0; i