sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit c59894bd5c41f2d4b4a03755a8aefbf470be28f2
parent 5773a8f22b400601ec82cc6b199b160a1d1cca22
Author: sin <sin@2f30.org>
Date:   Thu, 13 Nov 2014 14:15:20 +0000

Implement cat -u and report correct exit condition

Diffstat:
Mcat.c | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/cat.c b/cat.c @@ -9,7 +9,7 @@ static void usage(void) { - eprintf("usage: %s [file...]\n", argv0); + eprintf("usage: %s [-u] [file...]\n", argv0); } int @@ -17,9 +17,12 @@ main(int argc, char *argv[]) { char *p; FILE *fp; - int i; + int ret = 0; ARGBEGIN { + case 'u': + setbuf(stdout, NULL); + break; default: usage(); } ARGEND; @@ -27,17 +30,18 @@ main(int argc, char *argv[]) if(argc == 0) { concat(stdin, "<stdin>", stdout, "<stdout>"); } else { - for(i = 0; i < argc; i++) { - p = argv[i]; - if (argv[i][0] == '-') + for (; argc; argc--, argv++) { + p = argv[0]; + if (argv[0][0] == '-') p = "/dev/fd/0"; if(!(fp = fopen(p, "r"))) { - weprintf("fopen %s:", argv[i]); + weprintf("fopen %s:", p); + ret = 1; continue; } concat(fp, p, stdout, "<stdout>"); fclose(fp); } } - return 0; + return ret; }