Implement cat -u and report correct exit condition

This commit is contained in:
sin 2014-11-13 14:15:20 +00:00
parent 5773a8f22b
commit c59894bd5c

18
cat.c
View File

@ -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;
}