Introduce old redir program
[lcapit-junk-code.git] / books / apue / cp.c
blob03c7de955f4900da17ee613aedd5a3292dba30a3
1 /*
2 * Copy standard input to standard output (slow way)
3 *
4 * Would probably faster if we:
5 *
6 * 1. get the BUFSIZE value from stat's st_blksize member
7 * 2. use the standard I/O functions
8 */
10 #include <stdio.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <errno.h>
15 #define BUFSIZE 8192
17 int main(void)
19 int n;
20 char buf[BUFSIZE];
22 while ((n = read(STDIN_FILENO, buf, BUFSIZE)) > 0)
23 if (write(STDOUT_FILENO, buf, n) != n)
24 strerror(errno);
26 if (n < 0)
27 strerror(errno);
29 return 0;