ch@dce.ie (Charles Bryant) (12/04/90)
In article <1990Dec4.105612.14422@dce.ie> I write: > See <1990Dec4.103255.14195@dce.ie> in alt.sources. Well I have just found out that our news feed has a problem with alt.sources so rather than disappoint all you eager readers who can't live without a new cat, here's the said feline: To use this you will need: read(2), write(2), open(2), close(2), exit(2) ---------------------------------------------------------------- /* cat.c - the infamous cat(1) without bell and whistles */ #include <fcntl.h> /* for O_RDONLY */ #include <stdio.h> /* for BUFSIZ only */ #define error(s) write(2, (s), sizeof(s)-1) #define fileerr(msg, fil) (error(msg), perror(fil), status=1) int status=0; /* exit status */ static void cat(fd, nam) int fd; char *nam; { for (;;) { char iobuff[BUFSIZ]; register numin; numin = read(fd, iobuff, sizeof(iobuff)); if (numin==0) return; if (numin < 0) { fileerr("Read error: ", nam); return; } { register written; for (written=0; written<numin;) { register i = write(1, iobuff+written, numin-written); if (i<0) { fileerr("Write error writing ", nam); exit(1); } written += i; } } } } int main(argc,argv) char **argv; int argc; { int i; if (argc==1) { cat(0, "<stdin>"); exit(status); } for (i=1; i<argc; i++) { int fd=open(argv[i], O_RDONLY); if (fd<0) { fileerr("Can't open ", argv[i]); continue; } cat(fd, argv[i]); if (close(fd)) fileerr("Error closing input file: ", argv[i]); } if (close(1)) fileerr("Error closing output: ","<stdout>"); exit(status); } -- Charles Bryant (ch@dce.ie) -- /usr/ch/.signature: Block device required -- Charles Bryant (ch@dce.ie) -- /usr/ch/.signature: Block device required