b763dddb2374b1bb5ffa35640f5f11fddca3485b
[pintos-anon] / grading / vm / mmap-read.c
1 #include <stdio.h>
2 #include <string.h>
3 #ifdef PINTOS
4 #include <syscall.h>
5 #else
6 #include "posix-compat.h"
7 #endif
8 #include "sample.inc"
9
10 #define ACTUAL ((void *) 0x10000000)
11
12 int
13 main (void) 
14 {
15   int fd;
16
17   printf ("(mmap-read) begin\n");
18
19   fd = open ("sample.txt");
20   if (fd < 0) 
21     {
22       printf ("(mmap-read) open() failed\n");
23       return 1;
24     }
25
26   if (!mmap (fd, ACTUAL, strlen (sample)))
27     {
28       printf ("(mmap-read) mmap() failed\n");
29       return 1;
30     }
31
32   if (memcmp (ACTUAL, sample, strlen (sample)))
33     {
34       printf ("(mmap-read) read of mmap'd file reported bad data\n");
35       return 1;
36     }
37
38   if (!munmap (ACTUAL, strlen (sample)))
39     {
40       printf ("(mmap-read) munmap() failed\n");
41       return 1;
42     }
43
44   close (fd);
45
46   /* Done. */
47   printf ("(mmap-read) end\n");
48
49   return 0;
50 }