sbase/cat.c

53 lines
824 B
C
Raw Normal View History

2011-05-22 21:36:34 -04:00
/* See LICENSE file for copyright and license details. */
#include <fcntl.h>
#include <string.h>
2011-05-24 06:05:36 -04:00
#include <unistd.h>
2011-05-22 21:36:34 -04:00
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-u] [file ...]\n", argv0);
}
2011-05-22 21:36:34 -04:00
int
main(int argc, char *argv[])
{
int fd, ret = 0;
2011-05-22 21:36:34 -04:00
2012-05-31 14:38:18 -04:00
ARGBEGIN {
case 'u':
break;
2012-05-31 14:38:18 -04:00
default:
usage();
} ARGEND
2012-05-31 14:38:18 -04:00
2015-03-16 05:36:36 -04:00
if (!argc) {
if (concat(0, "<stdin>", 1, "<stdout>") < 0)
ret = 1;
2014-04-22 06:43:01 -04:00
} else {
for (; *argv; argc--, argv++) {
if (!strcmp(*argv, "-")) {
*argv = "<stdin>";
fd = 0;
} else if ((fd = open(*argv, O_RDONLY)) < 0) {
weprintf("open %s:", *argv);
ret = 1;
continue;
2014-04-22 06:43:01 -04:00
}
switch (concat(fd, *argv, 1, "<stdout>")) {
case -1:
ret = 1;
break;
case -2:
return 1; /* exit on write error */
}
if (fd != 0)
close(fd);
}
2011-05-22 21:36:34 -04:00
}
return ret;
2011-05-22 21:36:34 -04:00
}