pintos: Avoid literal control character in Perl variable name.
[pintos-anon] / src / examples / mcat.c
1 /* mcat.c
2
3    Prints files specified on command line to the console, using
4    mmap. */
5
6 #include <stdio.h>
7 #include <syscall.h>
8
9 int
10 main (int argc, char *argv[]) 
11 {
12   int i;
13   
14   for (i = 1; i < argc; i++) 
15     {
16       int fd;
17       mapid_t map;
18       void *data = (void *) 0x10000000;
19       int size;
20
21       /* Open input file. */
22       fd = open (argv[i]);
23       if (fd < 0) 
24         {
25           printf ("%s: open failed\n", argv[i]);
26           return EXIT_FAILURE;
27         }
28       size = filesize (fd);
29
30       /* Map files. */
31       map = mmap (fd, data);
32       if (map == MAP_FAILED) 
33         {
34           printf ("%s: mmap failed\n", argv[i]);
35           return EXIT_FAILURE;
36         }
37
38       /* Write file to console. */
39       write (STDOUT_FILENO, data, size);
40
41       /* Unmap files (optional). */
42       munmap (map);
43     }
44   return EXIT_SUCCESS;
45 }