Commit | Line | Data |
---|---|---|
91978b44 ES |
1 | /* |
2 | ||
3 | filecat | |
4 | ||
5 | does nothing more than copy standard input to standard | |
6 | output, like the cat command, but reports write errors. | |
7 | Takes no arguments. | |
8 | Uses getc and putc rather than fwrite and fread because | |
9 | the latter call getc and putc. | |
10 | ||
11 | Exit codes: | |
12 | 0 ok | |
13 | 1 error on read | |
14 | 2 error on write | |
15 | ||
16 | */ | |
17 | # include <stdio.h> | |
18 | main(){ | |
19 | char c,sOutbuf[BUFSIZ]; | |
20 | ||
21 | setbuf(stdout,sOutbuf); | |
22 | ||
23 | while((c = getc(stdin)) != EOF){ | |
24 | putc(c,stdout); | |
25 | if(ferror(stdout)){ | |
26 | perror("filecat: stdout"); | |
27 | exit(2); | |
28 | } | |
29 | } | |
30 | if(ferror(stdin)){ | |
31 | perror("filecat: stdin"); | |
32 | exit(1); | |
33 | } | |
34 | fclose(stdin); | |
35 | fclose(stdout); | |
36 | exit(0); | |
37 | } |