diff options
author | rsc <rsc> | 2007-08-24 20:03:40 +0000 |
---|---|---|
committer | rsc <rsc> | 2007-08-24 20:03:40 +0000 |
commit | 1b789e1d50df4e7b98fa131fc29caf29a5f38bfa (patch) | |
tree | d3a2bd24a03aaede0a51b8e5938db6d55753e96a /cat.c | |
parent | 8e88f9e2c617cc1002039c6e37c3c831319b1f8f (diff) | |
download | xv6-labs-1b789e1d50df4e7b98fa131fc29caf29a5f38bfa.tar.gz xv6-labs-1b789e1d50df4e7b98fa131fc29caf29a5f38bfa.tar.bz2 xv6-labs-1b789e1d50df4e7b98fa131fc29caf29a5f38bfa.zip |
Remove puts in favor of printf.
Allow multiple arguments to ls.
Diffstat (limited to 'cat.c')
-rw-r--r-- | cat.c | 35 |
1 files changed, 15 insertions, 20 deletions
@@ -2,19 +2,17 @@ #include "stat.h" #include "user.h" -char buf[513]; +char buf[512]; void rfile(int fd) { - int cc; + int n; - while((cc = read(fd, buf, sizeof(buf) - 1)) > 0){ - buf[cc] = '\0'; - puts(buf); - } - if(cc < 0){ - puts("cat: read error\n"); + while((n = read(fd, buf, sizeof(buf))) > 0) + write(1, buf, n); + if(n < 0){ + printf(1, "cat: read error\n"); exit(); } } @@ -26,19 +24,16 @@ main(int argc, char *argv[]) if(argc <= 1) { rfile(0); - } else { - for(i = 1; i < argc; i++){ - fd = open(argv[i], 0); - if(fd < 0){ - puts("cat: cannot open "); - puts(argv[i]); - puts("\n"); - exit(); - } - rfile(fd); - close(fd); - } + exit(); } + for(i = 1; i < argc; i++){ + if((fd = open(argv[i], 0)) < 0){ + printf(1, "cat: cannot open %s\n", argv[i]); + exit(); + } + rfile(fd); + close(fd); + } exit(); } |