rsc | bc7cb1a | 2003-11-23 18:04:47 +0000 | [diff] [blame] | 1 | #include <u.h> |
| 2 | #include <libc.h> |
| 3 | |
| 4 | void |
| 5 | cat(int f, char *s) |
| 6 | { |
| 7 | char buf[8192]; |
| 8 | long n; |
| 9 | |
| 10 | while((n=read(f, buf, (long)sizeof buf))>0) |
| 11 | if(write(1, buf, n)!=n) |
| 12 | sysfatal("write error copying %s: %r", s); |
| 13 | if(n < 0) |
| 14 | sysfatal("error reading %s: %r", s); |
| 15 | } |
| 16 | |
| 17 | void |
| 18 | main(int argc, char *argv[]) |
| 19 | { |
| 20 | int f, i; |
| 21 | |
| 22 | argv0 = "cat"; |
| 23 | if(argc == 1) |
| 24 | cat(0, "<stdin>"); |
| 25 | else for(i=1; i<argc; i++){ |
| 26 | f = open(argv[i], OREAD); |
| 27 | if(f < 0) |
| 28 | sysfatal("can't open %s: %r", argv[i]); |
| 29 | else{ |
| 30 | cat(f, argv[i]); |
| 31 | close(f); |
| 32 | } |
| 33 | } |
| 34 | exits(0); |
| 35 | } |
| 36 | |