2006-06-03 02:26:16 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2003-11-14 15:34:33 +05:30
|
|
|
/*
|
|
|
|
* Monitor a pipe with a simple progress display.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 by Rob Landley <rob@landley.net>, Joey Hess
|
|
|
|
*
|
2006-06-03 02:26:16 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2003-11-14 15:34:33 +05:30
|
|
|
*/
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2003-11-14 15:34:33 +05:30
|
|
|
|
|
|
|
#define PIPE_PROGRESS_SIZE 4096
|
|
|
|
|
2006-06-03 02:26:16 +05:30
|
|
|
/* Read a block of data from stdin, write it to stdout.
|
|
|
|
* Activity is indicated by a '.' to stderr
|
2003-11-14 15:34:33 +05:30
|
|
|
*/
|
2007-10-11 15:35:36 +05:30
|
|
|
int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
2003-11-14 15:34:33 +05:30
|
|
|
{
|
2010-06-06 21:49:25 +05:30
|
|
|
char buf[PIPE_PROGRESS_SIZE];
|
2003-11-14 15:34:33 +05:30
|
|
|
time_t t = time(NULL);
|
2010-06-06 21:49:25 +05:30
|
|
|
int len;
|
2003-11-14 15:34:33 +05:30
|
|
|
|
2010-06-06 21:49:25 +05:30
|
|
|
while ((len = safe_read(STDIN_FILENO, buf, PIPE_PROGRESS_SIZE)) > 0) {
|
2003-11-14 15:34:33 +05:30
|
|
|
time_t new_time = time(NULL);
|
|
|
|
if (new_time != t) {
|
|
|
|
t = new_time;
|
|
|
|
fputc('.', stderr);
|
|
|
|
}
|
2010-06-06 21:49:25 +05:30
|
|
|
full_write(STDOUT_FILENO, buf, len);
|
2003-11-14 15:34:33 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
fputc('\n', stderr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|