0a15f8cdc2fa1bd851b33523dfef7e79c189ca02
[lunaix-os.git] / lunaix-os / usr / cat / main.c
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <unistd.h>
5
6 #define BUFSIZE 4096
7
8 static char buffer[BUFSIZE];
9
10 int
11 main(int argc, const char* argv[])
12 {
13     int fd = 0;
14     unsigned int size = 0;
15     for (int i = 1; i < argc; i++) {
16         fd = open(argv[i], FO_RDONLY);
17         if (fd < 0) {
18             printf("open failed: %s (error: %d)", argv[i], fd);
19             continue;
20         }
21
22         do {
23             size = read(fd, buffer, BUFSIZE);
24             write(stdout, buffer, size);
25         } while (size == BUFSIZE);
26
27         close(fd);
28     }
29
30     return 0;
31 }