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 | */ |
| 9 | |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 10 | #include "busybox.h" |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
Glenn L McGrath | d0550d8 | 2003-11-21 21:54:07 +0000 | [diff] [blame] | 12 | #include <stdlib.h> |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 13 | #include <unistd.h> |
| 14 | #include <time.h> |
| 15 | |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 16 | #define PIPE_PROGRESS_SIZE 4096 |
| 17 | |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 18 | /* Read a block of data from stdin, write it to stdout. |
| 19 | * Activity is indicated by a '.' to stderr |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 20 | */ |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 21 | int pipe_progress_main(int argc, char **argv) |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 22 | { |
| 23 | RESERVE_CONFIG_BUFFER(buf, PIPE_PROGRESS_SIZE); |
| 24 | time_t t = time(NULL); |
| 25 | size_t len; |
| 26 | |
| 27 | while ((len = fread(buf, 1, PIPE_PROGRESS_SIZE, stdin)) > 0) { |
| 28 | time_t new_time = time(NULL); |
| 29 | if (new_time != t) { |
| 30 | t = new_time; |
| 31 | fputc('.', stderr); |
| 32 | } |
| 33 | fwrite(buf, len, 1, stdout); |
| 34 | } |
| 35 | |
| 36 | fputc('\n', stderr); |
| 37 | |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 38 | if (ENABLE_FEATURE_CLEAN_UP) |
| 39 | RELEASE_CONFIG_BUFFER(buf); |
| 40 | |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 41 | return 0; |
| 42 | } |