blob: 51a017c988b34b0f3f1ddf1b82880e400df9d6ab [file] [log] [blame]
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrathe9080c92003-11-14 10:04:33 +00002/*
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-Fischere15d7572006-06-02 20:56:16 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Glenn L McGrathe9080c92003-11-14 10:04:33 +00008 */
9
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000010#include "busybox.h"
Glenn L McGrathe9080c92003-11-14 10:04:33 +000011#include <stdio.h>
Glenn L McGrathd0550d82003-11-21 21:54:07 +000012#include <stdlib.h>
Glenn L McGrathe9080c92003-11-14 10:04:33 +000013#include <unistd.h>
14#include <time.h>
15
Glenn L McGrathe9080c92003-11-14 10:04:33 +000016#define PIPE_PROGRESS_SIZE 4096
17
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000018/* Read a block of data from stdin, write it to stdout.
19 * Activity is indicated by a '.' to stderr
Glenn L McGrathe9080c92003-11-14 10:04:33 +000020 */
Denis Vlasenko06af2162007-02-03 17:28:39 +000021int pipe_progress_main(int argc, char **argv);
Rob Landleydfba7412006-03-06 20:47:33 +000022int pipe_progress_main(int argc, char **argv)
Glenn L McGrathe9080c92003-11-14 10:04:33 +000023{
24 RESERVE_CONFIG_BUFFER(buf, PIPE_PROGRESS_SIZE);
25 time_t t = time(NULL);
26 size_t len;
27
28 while ((len = fread(buf, 1, PIPE_PROGRESS_SIZE, stdin)) > 0) {
29 time_t new_time = time(NULL);
30 if (new_time != t) {
31 t = new_time;
32 fputc('.', stderr);
33 }
34 fwrite(buf, len, 1, stdout);
35 }
36
37 fputc('\n', stderr);
38
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000039 if (ENABLE_FEATURE_CLEAN_UP)
40 RELEASE_CONFIG_BUFFER(buf);
41
Glenn L McGrathe9080c92003-11-14 10:04:33 +000042 return 0;
43}