sbase/cat.c
FRIGN d806f75cb6 Audit cat(1)
1) Fix usage ... spacing
2) use *argv instead of argv[0] in the idiomatic for-loop
3) Stop the naïve usage of "/dev/fd/0" and use plain stdin
   instead (This also makes error-messages more consistent).
4) Add newline before return
5) Remove comma in manpage
2015-03-02 00:39:26 +01:00

46 lines
757 B
C

/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <unistd.h>
#include "text.h"
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-u] [file ...]\n", argv0);
}
int
main(int argc, char *argv[])
{
FILE *fp;
int ret = 0;
ARGBEGIN {
case 'u':
setbuf(stdout, NULL);
break;
default:
usage();
} ARGEND;
if (argc == 0) {
concat(stdin, "<stdin>", stdout, "<stdout>");
} else {
for (; argc > 0; argc--, argv++) {
if ((*argv)[0] == '-' && !(*argv)[1]) {
concat(stdin, "<stdin>", stdout, "<stdout>");
} else if (!(fp = fopen(*argv, "r"))) {
weprintf("fopen %s:", *argv);
ret = 1;
} else {
concat(fp, *argv, stdout, "<stdout>");
fclose(fp);
}
}
}
return ret;
}