added base src
[xv6-db.git] / cat.c
blob2b2dcc7a5642d72c5bd358636940ca1d4fdd20a6
1 #include "types.h"
2 #include "stat.h"
3 #include "user.h"
5 char buf[512];
7 void
8 cat(int fd)
10 int n;
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();
20 int
21 main(int argc, char *argv[])
23 int fd, i;
25 if(argc <= 1){
26 cat(0);
27 exit();
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();
35 cat(fd);
36 close(fd);
38 exit();