diff options
author | rsc <devnull@localhost> | 2003-11-23 18:04:47 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-11-23 18:04:47 +0000 |
commit | bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d (patch) | |
tree | 8ca0fe4e2418e6aa18dc74a236c577a719f6c6ed /src/cmd/cat.c | |
parent | f08fdedcee12c06e3ce9ac9bec363915978e8289 (diff) | |
download | plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.gz plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.bz2 plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.zip |
new utilities.
the .C files compile but are renamed to avoid building automatically.
Diffstat (limited to 'src/cmd/cat.c')
-rw-r--r-- | src/cmd/cat.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/cmd/cat.c b/src/cmd/cat.c new file mode 100644 index 00000000..ac588897 --- /dev/null +++ b/src/cmd/cat.c @@ -0,0 +1,36 @@ +#include <u.h> +#include <libc.h> + +void +cat(int f, char *s) +{ + char buf[8192]; + long n; + + while((n=read(f, buf, (long)sizeof buf))>0) + if(write(1, buf, n)!=n) + sysfatal("write error copying %s: %r", s); + if(n < 0) + sysfatal("error reading %s: %r", s); +} + +void +main(int argc, char *argv[]) +{ + int f, i; + + argv0 = "cat"; + if(argc == 1) + cat(0, "<stdin>"); + else for(i=1; i<argc; i++){ + f = open(argv[i], OREAD); + if(f < 0) + sysfatal("can't open %s: %r", argv[i]); + else{ + cat(f, argv[i]); + close(f); + } + } + exits(0); +} + |