c60ab27bc6e22bee4fae7a0aa6c02cb53008e365
[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         fd = open(argv[1], OPENFLAG_READ);
22         if(fd == -1) {
23                 printf("Unable to open '%s' for reading\n", argv[1]);
24                 return -1;
25         }
26
27         do {
28                 num = read(fd, BUF_SIZE, buf);
29                 printf("num = %i\n", num);
30                 buf[num] = '\0';
31                 printf("%s", buf);
32         } while(num == BUF_SIZE);
33
34         close(fd);
35         printf("\n");
36
37         return 0;
38 }

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