summaryrefslogtreecommitdiffstats
path: root/pintos-progos/examples/mcat.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
committermanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
commitb5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch)
tree1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/examples/mcat.c
downloadprogos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip
initial pintos checkin
Diffstat (limited to 'pintos-progos/examples/mcat.c')
-rw-r--r--pintos-progos/examples/mcat.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/pintos-progos/examples/mcat.c b/pintos-progos/examples/mcat.c
new file mode 100644
index 0000000..7b39760
--- /dev/null
+++ b/pintos-progos/examples/mcat.c
@@ -0,0 +1,45 @@
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
9int
10main (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}