a7f3ab323e1a24334c92120883156739058112cc
[tpg/acess2.git] / Usermode / Applications / cat_src / main.c
1 /*
2  * Acess2 CAT command
3  */
4 #include <acess/sys.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7
8 #define BUF_SIZE        1024
9
10 int main(int argc, char *argv[])
11 {
12          int    fd;
13          int    num;
14         char    buf[BUF_SIZE+1];
15
16         if(argc < 2) {
17                 printf("Usage: cat <file>\n");
18                 return -1;
19         }
20
21         //printf("Contents of `%s'\n", argv[1]);
22         fd = open(argv[1], OPENFLAG_READ);
23         if(fd == -1) {
24                 printf("Unable to open '%s' for reading\n", argv[1]);
25                 return -1;
26         }
27
28         do {
29                 num = read(fd, BUF_SIZE, buf);
30                 //printf("num = %i\n", num);
31                 buf[num] = '\0';
32                 printf("%s", buf);
33         } while(num == BUF_SIZE);
34
35         close(fd);
36         printf("\n");
37
38         return 0;
39 }

UCC git Repository :: git.ucc.asn.au