Home | History | Annotate | Download | only in other
      1 /* count.c - Progress indicator from stdin to stdout
      2  *
      3  * Copyright 2002 Rob Landley <rob (at) landley.net>
      4 
      5 USE_COUNT(NEWTOY(count, NULL, TOYFLAG_USR|TOYFLAG_BIN))
      6 
      7 config COUNT
      8   bool "count"
      9   default y
     10   help
     11     usage: count
     12 
     13     Copy stdin to stdout, displaying simple progress indicator to stderr.
     14 */
     15 
     16 #include "toys.h"
     17 
     18 void count_main(void)
     19 {
     20   uint64_t size = 0;
     21   int len;
     22   char buf[32];
     23 
     24   for (;;) {
     25     len = xread(0, toybuf, sizeof(toybuf));
     26     if (!len) break;
     27     size += len;
     28     xwrite(1, toybuf, len);
     29     xwrite(2, buf, sprintf(buf, "%"PRIu64" bytes\r", size));
     30   }
     31   xwrite(2, "\n", 1);
     32 }
     33