Mercurial > hg > toybox
annotate toys/count.c @ 241:4121825716b8
Fix crash when running unknown command via symlink.
(The error message was trying to print an uninitialied field. Oops.)
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 22 Jan 2008 15:33:50 -0600 |
parents | 163498bf547b |
children | 5ab9d0e5e0f8 |
rev | line source |
---|---|
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
1 /* vi: set sw=4 ts=4: |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
2 * |
86
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * count.c - Progress indicator from stdin to stdout |
194
30a6db5a95c2
Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
4 * |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
5 * Copyright 2002 Rob Landley <rob@landley.net> |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
6 * |
194
30a6db5a95c2
Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
7 * Not in SUSv3. |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
8 |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
9 USE_COUNT(NEWTOY(count, NULL, TOYFLAG_USR|TOYFLAG_BIN)) |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
10 |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
11 config COUNT |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
12 bool "count" |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
13 default y |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
14 help |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
15 usage: count |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
16 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
17 Copy stdin to stdout, displaying simple progress indicator to stderr. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
194
diff
changeset
|
18 */ |
86
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 #include "toys.h" |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 |
186
25447caf1b4b
Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents:
86
diff
changeset
|
22 void count_main(void) |
86
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 { |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 uint64_t size = 0; |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 int len; |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 for (;;) { |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 len = xread(0, toybuf, sizeof(toybuf)); |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 if (!len) break; |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 size += len; |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 xwrite(1, toybuf, sizeof(toybuf)); |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 fdprintf(2, "%"PRIu64" bytes\r", size); |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 } |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 fdprintf(2,"\n"); |
d2e38cb0b1cd
I forgot to add count.c a while ago. (Memo to self: grab snapshots and build
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 } |