[hackers] [sbase] Implement cat -u and report correct exit condition || sin
commit c59894bd5c41f2d4b4a03755a8aefbf470be28f2
Author: sin <sin_AT_2f30.org>
Date: Thu Nov 13 14:15:20 2014 +0000
Implement cat -u and report correct exit condition
diff --git a/cat.c b/cat.c
index a7c07c9..67dac13 100644
--- a/cat.c
+++ b/cat.c
_AT_@ -9,7 +9,7 @@
static void
usage(void)
{
- eprintf("usage: %s [file...]\n", argv0);
+ eprintf("usage: %s [-u] [file...]\n", argv0);
}
int
_AT_@ -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;
_AT_@ -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;
}
Received on Thu Nov 13 2014 - 15:56:20 CET
This archive was generated by hypermail 2.3.0
: Thu Nov 13 2014 - 16:00:16 CET