Last active
October 9, 2015 06:03
-
-
Save ph1ee/9fda8d520184dd1eb0b3 to your computer and use it in GitHub Desktop.
Progress Pipe: Read a block of data from stdin, write it to stdout. Activity is indicated by a '.' to stderr.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <time.h> | |
#define PIPE_PROGRESS_SIZE 4096 | |
/* Read a block of data from stdin, write it to stdout. | |
* Activity is indicated by a '.' to stderr | |
*/ | |
int main(int argc, char **argv) | |
{ | |
char buf[PIPE_PROGRESS_SIZE]; | |
time_t t = time(NULL); | |
size_t len; | |
while ((len = fread(buf, 1, PIPE_PROGRESS_SIZE, stdin)) > 0) { | |
time_t new_time = time(NULL); | |
if (new_time != t) { | |
t = new_time; | |
fputc('.', stderr); | |
} | |
fwrite(buf, 1, len, stdout); | |
} | |
fputc('\n', stderr); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment