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