Mercurial > hg > Members > anatofuz > CbC_xv6
comparison src/usr/cat.c @ 0:83c23a36980d
Init
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 26 May 2017 23:11:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:83c23a36980d |
---|---|
1 #include "types.h" | |
2 #include "stat.h" | |
3 #include "user.h" | |
4 | |
5 char buf[512]; | |
6 | |
7 void | |
8 cat(int fd) | |
9 { | |
10 int n; | |
11 | |
12 while((n = read(fd, buf, sizeof(buf))) > 0) | |
13 write(1, buf, n); | |
14 if(n < 0){ | |
15 printf(1, "cat: read error\n"); | |
16 exit(); | |
17 } | |
18 } | |
19 | |
20 int | |
21 main(int argc, char *argv[]) | |
22 { | |
23 int fd, i; | |
24 | |
25 if(argc <= 1){ | |
26 cat(0); | |
27 exit(); | |
28 } | |
29 | |
30 for(i = 1; i < argc; i++){ | |
31 if((fd = open(argv[i], 0)) < 0){ | |
32 printf(1, "cat: cannot open %s\n", argv[i]); | |
33 exit(); | |
34 } | |
35 cat(fd); | |
36 close(fd); | |
37 } | |
38 exit(); | |
39 } |