Add some more examples.
[pintos-anon] / src / examples / cat.c
1 /* cat.c
2
3    Prints files specified on command line to the console. */
4
5 #include <stdio.h>
6 #include <syscall.h>
7
8 int
9 main (int argc, char *argv[]) 
10 {
11   int i;
12   
13   for (i = 1; i < argc; i++) 
14     {
15       int fd = open (argv[i]);
16       if (fd < 0) 
17         {
18           printf ("%s: open failed\n", argv[i]);
19           continue;
20         }
21       for (;;) 
22         {
23           char buffer[1024];
24           int bytes_read = read (fd, buffer, sizeof buffer);
25           if (bytes_read == 0)
26             break;
27           write (STDOUT_FILENO, buffer, bytes_read);
28         }
29       close (fd);
30     }
31   return 0;
32 }