Annotation of /trunk/mkinitrd-magellan/busybox/debianutils/pipe_progress.c
Parent Directory
|
Revision Log
Revision 816 -
(hide annotations)
(download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 919 byte(s)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 919 byte(s)
-updated to busybox-1.13.4
1 | niro | 532 | /* 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 tarball for details. | ||
8 | */ | ||
9 | |||
10 | niro | 816 | #include "libbb.h" |
11 | niro | 532 | |
12 | #define PIPE_PROGRESS_SIZE 4096 | ||
13 | |||
14 | /* Read a block of data from stdin, write it to stdout. | ||
15 | * Activity is indicated by a '.' to stderr | ||
16 | */ | ||
17 | niro | 816 | int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
18 | int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | ||
19 | niro | 532 | { |
20 | RESERVE_CONFIG_BUFFER(buf, PIPE_PROGRESS_SIZE); | ||
21 | time_t t = time(NULL); | ||
22 | size_t len; | ||
23 | |||
24 | while ((len = fread(buf, 1, PIPE_PROGRESS_SIZE, stdin)) > 0) { | ||
25 | time_t new_time = time(NULL); | ||
26 | if (new_time != t) { | ||
27 | t = new_time; | ||
28 | fputc('.', stderr); | ||
29 | } | ||
30 | fwrite(buf, len, 1, stdout); | ||
31 | } | ||
32 | |||
33 | fputc('\n', stderr); | ||
34 | |||
35 | if (ENABLE_FEATURE_CLEAN_UP) | ||
36 | RELEASE_CONFIG_BUFFER(buf); | ||
37 | |||
38 | return 0; | ||
39 | } |