blob: 2c7444f3118b0ece3e853d2c6053cbab99db2c1a
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * Monitor a pipe with a simple progress display. |
4 | * |
5 | * Copyright (C) 2003 by Rob Landley <rob@landley.net>, Joey Hess |
6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ |
9 | |
10 | //usage:#define pipe_progress_trivial_usage NOUSAGE_STR |
11 | //usage:#define pipe_progress_full_usage "" |
12 | |
13 | #include "libbb.h" |
14 | |
15 | #define PIPE_PROGRESS_SIZE 4096 |
16 | |
17 | /* Read a block of data from stdin, write it to stdout. |
18 | * Activity is indicated by a '.' to stderr |
19 | */ |
20 | int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
21 | int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
22 | { |
23 | char buf[PIPE_PROGRESS_SIZE]; |
24 | time_t t = time(NULL); |
25 | int len; |
26 | |
27 | while ((len = safe_read(STDIN_FILENO, buf, PIPE_PROGRESS_SIZE)) > 0) { |
28 | time_t new_time = time(NULL); |
29 | if (new_time != t) { |
30 | t = new_time; |
31 | bb_putchar_stderr('.'); |
32 | } |
33 | full_write(STDOUT_FILENO, buf, len); |
34 | } |
35 | |
36 | bb_putchar_stderr('\n'); |
37 | |
38 | return 0; |
39 | } |
40 |