3
0

pipe_progress.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* 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 source tree.
  8. */
  9. //config:config PIPE_PROGRESS
  10. //config: bool "pipe_progress (576 bytes)"
  11. //config: default y
  12. //config: help
  13. //config: Display a dot to indicate pipe activity.
  14. //applet:IF_PIPE_PROGRESS(APPLET(pipe_progress, BB_DIR_BIN, BB_SUID_DROP))
  15. //kbuild:lib-$(CONFIG_PIPE_PROGRESS) += pipe_progress.o
  16. //usage:#define pipe_progress_trivial_usage NOUSAGE_STR
  17. //usage:#define pipe_progress_full_usage ""
  18. #include "libbb.h"
  19. #define PIPE_PROGRESS_SIZE 4096
  20. /* Read a block of data from stdin, write it to stdout.
  21. * Activity is indicated by a '.' to stderr
  22. */
  23. int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  24. int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  25. {
  26. char buf[PIPE_PROGRESS_SIZE];
  27. time_t t = time(NULL);
  28. int len;
  29. while ((len = safe_read(STDIN_FILENO, buf, PIPE_PROGRESS_SIZE)) > 0) {
  30. time_t new_time = time(NULL);
  31. if (new_time != t) {
  32. t = new_time;
  33. bb_putchar_stderr('.');
  34. }
  35. full_write(STDOUT_FILENO, buf, len);
  36. }
  37. bb_putchar_stderr('\n');
  38. return 0;
  39. }