depmaker
[tridge/junkcode.git] / mmap.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <sys/mman.h>
4 #include <fcntl.h>
5 #include <sys/file.h>
6
7 int main(void)
8 {
9         int fd, fd2;
10         char buf[1024]="";
11         int i;
12         char *p;
13
14         memset(buf,'Z', sizeof(buf));
15
16         fd = open("mmap.tst", O_WRONLY|O_CREAT|O_TRUNC, 0600);
17
18         for (i=0;i<32;i++) {
19                 write(fd, buf, sizeof(buf));
20         }
21
22         close(fd);
23
24         fd = open("mmap.tst", O_RDONLY);
25
26         p = mmap(NULL, i*sizeof(buf), PROT_READ, MAP_SHARED, fd, 0);
27
28         truncate("mmap.tst", 0);
29
30         fd2 = open("mmap.tst.2", O_WRONLY|O_TRUNC|O_CREAT, 0600);
31
32         printf("accessing ...\n");
33
34         write(fd2, p, i*sizeof(buf));
35
36         close(fd2);
37
38         return 0;
39 }