comparison toys/cat.c @ 313:d1ae502ee190

An error from an input file isn't fatal, keep reading remaining input files.
author Rob Landley <rob@landley.net>
date Fri, 15 Aug 2008 14:16:53 -0500
parents 1c160cadf5b9
children
comparison
equal deleted inserted replaced
312:064fc1b8b7b1 313:d1ae502ee190
1 /* vi: set sw=4 ts=4: 1 /* vi: set sw=4 ts=4:
2 * 2 *
3 * hello.c - A hello world program. 3 * cat.c - copy inputs to stdout.
4 * 4 *
5 * Copyright 2006 Rob Landley <rob@landley.net> 5 * Copyright 2006 Rob Landley <rob@landley.net>
6 * 6 *
7 * See http://www.opengroup.org/onlinepubs/009695399/utilities/cat.html 7 * See http://www.opengroup.org/onlinepubs/009695399/utilities/cat.html
8 8
12 bool "cat" 12 bool "cat"
13 default y 13 default y
14 help 14 help
15 usage: cat [-u] [file...] 15 usage: cat [-u] [file...]
16 Copy (concatenate) files to stdout. If no files listed, copy from stdin. 16 Copy (concatenate) files to stdout. If no files listed, copy from stdin.
17 Filename "-" is a synonym for stdin.
17 18
18 -u Copy one byte at a time (slow). 19 -u Copy one byte at a time (slow).
19 */ 20 */
20 21
21 #include "toys.h" 22 #include "toys.h"
23 static void do_cat(int fd, char *name) 24 static void do_cat(int fd, char *name)
24 { 25 {
25 int len, size=toys.optflags ? 1 : sizeof(toybuf); 26 int len, size=toys.optflags ? 1 : sizeof(toybuf);
26 27
27 for (;;) { 28 for (;;) {
28 len = xread(fd, toybuf, size); 29 len = read(fd, toybuf, size);
29 if (len<0) toys.exitval = EXIT_FAILURE; 30 if (len<0) {
31 perror_msg("%s",name);
32 toys.exitval = EXIT_FAILURE;
33 }
30 if (len<1) break; 34 if (len<1) break;
31 xwrite(1, toybuf, len); 35 xwrite(1, toybuf, len);
32 } 36 }
33 } 37 }
34 38