comparison toys/cat.c @ 279:0ca2fcee572b

Spent the five minutes to implement "cat".
author Rob Landley <rob@landley.net>
date Fri, 04 Apr 2008 12:19:21 -0500
parents
children 1c160cadf5b9
comparison
equal deleted inserted replaced
278:4fa9937b0073 279:0ca2fcee572b
1 /* vi: set sw=4 ts=4:
2 *
3 * hello.c - A hello world program.
4 *
5 * Copyright 2006 Rob Landley <rob@landley.net>
6 *
7 * See http://www.opengroup.org/onlinepubs/009695399/utilities/cat.html
8
9 USE_CAT(NEWTOY(cat, "u", TOYFLAG_BIN))
10
11 config CAT
12 bool "cat"
13 default y
14 help
15 usage: cat [-u] [file...]
16 Copy (concatenate) files to stdout. If no files listed, copy from stdin.
17
18 -u Copy one byte at a time (slow).
19 */
20
21 #include "toys.h"
22
23 static void do_cat(int fd, char *name)
24 {
25 int len, size=toys.optflags ? 1 : sizeof(toybuf);
26
27 for (;;) {
28 len = xread(fd, toybuf, size);
29 if (len<0) toys.exitval = EXIT_FAILURE;
30 if (len<1) break;
31 xwrite(1, toybuf, size);
32 }
33 }
34
35 void cat_main(void)
36 {
37 loopfiles(toys.optargs, do_cat);
38 }