X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=listati%2Ftee.c;h=d0a31f2fb0b99c028d6e76f57dd4292ef0ae5642;hp=51df9f665667c9e6e2dbaae7a2cc5aed20fa21b4;hb=7e19b798d0cc09960daad695d8f3b242170bb3b4;hpb=fc2954a94ffab07871f49e2432d5223f55840fbf diff --git a/listati/tee.c b/listati/tee.c index 51df9f6..d0a31f2 100644 --- a/listati/tee.c +++ b/listati/tee.c @@ -7,36 +7,10 @@ int main(int argc, char *argv[]) int fd, len, nwrite; struct stat fdata; ... - /* check argument, open destination file and check stdin and stdout */ - if ((argc - optind) != 1) { /* There must be one argument */ - printf("Wrong number of arguments %d\n", argc - optind); - usage(); - } - fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (fd == -1) { - printf("opening file %s falied: %s", argv[1], strerror(errno)); - exit(EXIT_FAILURE); - } - if (fstat(STDIN_FILENO, &fdata) < 0) { - perror("cannot stat stdin"); - exit(EXIT_FAILURE); - } - if (!S_ISFIFO(fdata.st_mode)) { - fprintf(stderr, "stdin must be a pipe\n"); - exit(EXIT_FAILURE); - } - if (fstat(STDOUT_FILENO, &fdata) < 0) { - perror("cannot stat stdout"); - exit(EXIT_FAILURE); - } - if (!S_ISFIFO(fdata.st_mode)) { - fprintf(stderr, "stdout must be a pipe\n"); - exit(EXIT_FAILURE); - } /* tee loop */ while (1) { /* copy stdin to stdout */ - len = tee(STDIN_FILENO, STDOUT_FILENO, size, SPLICE_F_NONBLOCK); + len = tee(STDIN_FILENO, STDOUT_FILENO, size, 0); if (len == 0) break; if (len < 0) { if (errno == EAGAIN) {