X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2Ftee.c;h=8c09ae35bae08e4ee7118a6be8a9f25ca7621e26;hp=559c94987cf010ed516e64cf280a96abbab8c731;hb=374461977afeaf3ec285f3d4f0f1d3b47f7e4043;hpb=fc2954a94ffab07871f49e2432d5223f55840fbf diff --git a/sources/tee.c b/sources/tee.c index 559c949..8c09ae3 100644 --- a/sources/tee.c +++ b/sources/tee.c @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) * Use getopt function */ opterr = 0; /* don't want writing to stderr */ - while ( (i = getopt(argc, argv, "h")) != -1) { + while ( (i = getopt(argc, argv, "hs:")) != -1) { switch (i) { /* * Handling options @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) usage(); return -1; break; - case 's': /* take wait time for childen */ + case 's': /* buffer size */ size = strtol(optarg, NULL, 10); /* convert input */ break; case '?': /* unrecognized options */ @@ -115,7 +115,8 @@ int main(int argc, char *argv[]) /* 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); + fprintf(stderr, "Copied %d byte\n", len); /* debug (use stderr!) */ if (len == 0) break; if (len < 0) { if (errno == EAGAIN) { @@ -125,7 +126,6 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } } - fprintf(stderr, "Copied %d byte\n", len); /* debug (use stderr!) */ /* write data to the file using splice */ while (len > 0) { nwrite = splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);