#include #include #include static void usage(void) { fmt·panic("usage: %s [-u] [file ...]\n", argv0); exits("usage"); } static void cat(int fd, char *s) { long n; char buf[8192]; while((n=read(fd, buf, sizeof(buf)))>0){ if(write(1, buf, n) != n) fmt·panic("write error copying %s: %r", s); } if(n<0) fmt·panic("error reading %s: %r", s); } int main(int argc, char *argv[]) { int fd; ARGBEGIN{ case 'u': /* ignore */ break; default: usage(); }ARGEND; if(!argc){ cat(0, ""); exits(0); } while(argc-- > 0){ if((fd = open(*argv, O_RDONLY))<0) fmt·panic("can't open %s: %r", *argv); cat(fd, *argv); close(fd); argv++; } }