added some tools from ronnie sahlberg
[tridge/junkcode.git] / mmap_write.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(int argc, const char *argv[])
8 {
9         int fd;
10         char *p;
11
12         fd = open(argv[1], O_RDWR, 0600);
13         if (fd == -1) {
14                 perror(argv[1]);
15                 return -1;
16         }
17
18         p = mmap(NULL, 4, PROT_WRITE, MAP_SHARED, fd, 0);
19         if (p == (void *)-1) {
20                 perror("mmap");
21                 return -1;
22         }
23
24         p[0]++;
25
26         munmap(p, 4);
27         close(fd);
28
29         return 0;
30 }