Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Monitor a pipe with a simple progress display. |
| 4 | * |
| 5 | * Copyright (C) 2003 by Rob Landley <rob@landley.net>, Joey Hess |
| 6 | * |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 8 | */ |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 9 | #include "libbb.h" |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 10 | |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 11 | #define PIPE_PROGRESS_SIZE 4096 |
| 12 | |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 13 | /* Read a block of data from stdin, write it to stdout. |
| 14 | * Activity is indicated by a '.' to stderr |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 15 | */ |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 16 | int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 17 | int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 18 | { |
Denys Vlasenko | 5f33037 | 2010-06-06 18:19:25 +0200 | [diff] [blame] | 19 | char buf[PIPE_PROGRESS_SIZE]; |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 20 | time_t t = time(NULL); |
Denys Vlasenko | 5f33037 | 2010-06-06 18:19:25 +0200 | [diff] [blame] | 21 | int len; |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 22 | |
Denys Vlasenko | 5f33037 | 2010-06-06 18:19:25 +0200 | [diff] [blame] | 23 | while ((len = safe_read(STDIN_FILENO, buf, PIPE_PROGRESS_SIZE)) > 0) { |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 24 | time_t new_time = time(NULL); |
| 25 | if (new_time != t) { |
| 26 | t = new_time; |
Denys Vlasenko | 19ced5c | 2010-06-06 21:53:09 +0200 | [diff] [blame] | 27 | bb_putchar_stderr('.'); |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 28 | } |
Denys Vlasenko | 5f33037 | 2010-06-06 18:19:25 +0200 | [diff] [blame] | 29 | full_write(STDOUT_FILENO, buf, len); |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Denys Vlasenko | 19ced5c | 2010-06-06 21:53:09 +0200 | [diff] [blame] | 32 | bb_putchar_stderr('\n'); |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 33 | |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 34 | return 0; |
| 35 | } |