blob: acc0c69f49a55801a8071c5cbc39067eaafb6638 [file] [log] [blame]
Rob Landley28964802008-01-19 17:08:39 -06001/* vi: set sw=4 ts=4:
2 *
Rob Landleyc555a0c2007-01-31 12:27:10 -05003 * count.c - Progress indicator from stdin to stdout
Rob Landleyfece5cb2007-12-03 20:05:57 -06004 *
Rob Landley28964802008-01-19 17:08:39 -06005 * Copyright 2002 Rob Landley <rob@landley.net>
6 *
Rob Landleyfece5cb2007-12-03 20:05:57 -06007 * Not in SUSv3.
Rob Landley28964802008-01-19 17:08:39 -06008
Rob Landley55928b12008-01-19 17:43:27 -06009USE_COUNT(NEWTOY(count, NULL, TOYFLAG_USR|TOYFLAG_BIN))
10
Rob Landley28964802008-01-19 17:08:39 -060011config COUNT
12 bool "count"
13 default y
14 help
15 usage: count
16
17 Copy stdin to stdout, displaying simple progress indicator to stderr.
18*/
Rob Landleyc555a0c2007-01-31 12:27:10 -050019
20#include "toys.h"
21
Rob Landleyefda21c2007-11-29 18:14:37 -060022void count_main(void)
Rob Landleyc555a0c2007-01-31 12:27:10 -050023{
24 uint64_t size = 0;
25 int len;
26
27 for (;;) {
28 len = xread(0, toybuf, sizeof(toybuf));
29 if (!len) break;
30 size += len;
Rob Landleycebe48a2008-08-28 17:32:05 -050031 xwrite(1, toybuf, len);
Rob Landleyc555a0c2007-01-31 12:27:10 -050032 fdprintf(2, "%"PRIu64" bytes\r", size);
33 }
34 fdprintf(2,"\n");
Rob Landleyc555a0c2007-01-31 12:27:10 -050035}