libc+AxWin3 - RichText rendering, scanf
[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 /**
11  * \fn int main(int argc, char *argv[])
12  * \brief Entrypoint
13  */
14 int main(int argc, char *argv[])
15 {
16          int    fd;
17          int    num;
18         char    buf[BUF_SIZE];
19
20         if(argc < 2) {
21                 printf("Usage: cat <file>\n");
22                 return -1;
23         }
24
25         fd = open(argv[1], OPENFLAG_READ);
26         if(fd == -1) {
27                 printf("Unable to open '%s' for reading\n", argv[1]);
28                 return -1;
29         }
30
31         do {
32                 num = read(fd, buf, BUF_SIZE);
33                 if(num < 0)     break;
34                 write(1, buf, num);
35         } while(num == BUF_SIZE);
36
37         close(fd);
38         printf("\n");
39
40         return 0;
41 }

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