summaryrefslogtreecommitdiff
path: root/cat.c
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-24 20:03:40 +0000
committerrsc <rsc>2007-08-24 20:03:40 +0000
commit1b789e1d50df4e7b98fa131fc29caf29a5f38bfa (patch)
treed3a2bd24a03aaede0a51b8e5938db6d55753e96a /cat.c
parent8e88f9e2c617cc1002039c6e37c3c831319b1f8f (diff)
downloadxv6-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.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/cat.c b/cat.c
index 6a54adf..0b98c74 100644
--- a/cat.c
+++ b/cat.c
@@ -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();
}