1 /* vi: set sw=4 ts=4: */
3 * Monitor a pipe with a simple progress display.
5 * Copyright (C) 2003 by Rob Landley <rob@landley.net>, Joey Hess
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 //config:config PIPE_PROGRESS
10 //config: bool "pipe_progress"
13 //config: Display a dot to indicate pipe activity.
15 //applet:IF_PIPE_PROGRESS(APPLET(pipe_progress, BB_DIR_BIN, BB_SUID_DROP))
17 //kbuild:lib-$(CONFIG_PIPE_PROGRESS) += pipe_progress.o
19 //usage:#define pipe_progress_trivial_usage NOUSAGE_STR
20 //usage:#define pipe_progress_full_usage ""
24 #define PIPE_PROGRESS_SIZE 4096
26 /* Read a block of data from stdin, write it to stdout.
27 * Activity is indicated by a '.' to stderr
29 int pipe_progress_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
30 int pipe_progress_main(int argc UNUSED_PARAM
, char **argv UNUSED_PARAM
)
32 char buf
[PIPE_PROGRESS_SIZE
];
33 time_t t
= time(NULL
);
36 while ((len
= safe_read(STDIN_FILENO
, buf
, PIPE_PROGRESS_SIZE
)) > 0) {
37 time_t new_time
= time(NULL
);
40 bb_putchar_stderr('.');
42 full_write(STDOUT_FILENO
, buf
, len
);
45 bb_putchar_stderr('\n');