Mercurial > hg > toybox
comparison toys/posix/cat.c @ 694:786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
The actual code should be the same afterward, this is just cosmetic refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 13 Nov 2012 17:14:08 -0600 |
parents | 6df4ccc0acbe |
children | 6cc69be43c42 |
comparison
equal
deleted
inserted
replaced
693:4a5a250e0633 | 694:786841fdb1e0 |
---|---|
1 /* vi: set sw=4 ts=4: | 1 /* cat.c - copy inputs to stdout. |
2 * | |
3 * cat.c - copy inputs to stdout. | |
4 * | 2 * |
5 * Copyright 2006 Rob Landley <rob@landley.net> | 3 * Copyright 2006 Rob Landley <rob@landley.net> |
6 * | 4 * |
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/cat.html | 5 * See http://opengroup.org/onlinepubs/9699919799/utilities/cat.html |
8 | 6 |
9 USE_CAT(NEWTOY(cat, "u", TOYFLAG_BIN)) | 7 USE_CAT(NEWTOY(cat, "u", TOYFLAG_BIN)) |
10 | 8 |
11 config CAT | 9 config CAT |
12 bool "cat" | 10 bool "cat" |
13 default y | 11 default y |
14 help | 12 help |
15 usage: cat [-u] [file...] | 13 usage: cat [-u] [file...] |
16 Copy (concatenate) files to stdout. If no files listed, copy from stdin. | 14 Copy (concatenate) files to stdout. If no files listed, copy from stdin. |
17 Filename "-" is a synonym for stdin. | 15 Filename "-" is a synonym for stdin. |
18 | 16 |
19 -u Copy one byte at a time (slow). | 17 -u Copy one byte at a time (slow). |
20 */ | 18 */ |
21 | 19 |
22 #include "toys.h" | 20 #include "toys.h" |
23 | 21 |
24 static void do_cat(int fd, char *name) | 22 static void do_cat(int fd, char *name) |
25 { | 23 { |
26 int len, size=toys.optflags ? 1 : sizeof(toybuf); | 24 int len, size=toys.optflags ? 1 : sizeof(toybuf); |
27 | 25 |
28 for (;;) { | 26 for (;;) { |
29 len = read(fd, toybuf, size); | 27 len = read(fd, toybuf, size); |
30 if (len<0) { | 28 if (len<0) { |
31 perror_msg("%s",name); | 29 perror_msg("%s",name); |
32 toys.exitval = EXIT_FAILURE; | 30 toys.exitval = EXIT_FAILURE; |
33 } | 31 } |
34 if (len<1) break; | 32 if (len<1) break; |
35 xwrite(1, toybuf, len); | 33 xwrite(1, toybuf, len); |
36 } | 34 } |
37 } | 35 } |
38 | 36 |
39 void cat_main(void) | 37 void cat_main(void) |
40 { | 38 { |
41 loopfiles(toys.optargs, do_cat); | 39 loopfiles(toys.optargs, do_cat); |
42 } | 40 } |