00001
00002
00003
00004 #if defined(HAVE_UNISTD_H)
00005 #include <unistd.h>
00006 #endif
00007 #include <sys/mman.h>
00008 #include <sys/types.h>
00009 #include <sys/stat.h>
00010 #include <fcntl.h>
00011
00012 #define DATA "conftest.mmap"
00013
00014 #ifndef MAP_FILE
00015 #define MAP_FILE 0
00016 #endif
00017
00018 main()
00019 {
00020 int *buf;
00021 int i;
00022 int fd = open(DATA,O_RDWR|O_CREAT|O_TRUNC,0666);
00023 int count=7;
00024
00025 if (fd == -1) exit(1);
00026
00027 for (i=0;i<10000;i++) {
00028 write(fd,&i,sizeof(i));
00029 }
00030
00031 close(fd);
00032
00033 if (fork() == 0) {
00034 fd = open(DATA,O_RDWR);
00035 if (fd == -1) exit(1);
00036
00037 buf = (int *)mmap(NULL, 10000*sizeof(int),
00038 (PROT_READ | PROT_WRITE),
00039 MAP_FILE | MAP_SHARED,
00040 fd, 0);
00041
00042 while (count-- && buf[9124] != 55732) sleep(1);
00043
00044 if (count <= 0) exit(1);
00045
00046 buf[1763] = 7268;
00047 exit(0);
00048 }
00049
00050 fd = open(DATA,O_RDWR);
00051 if (fd == -1) exit(1);
00052
00053 buf = (int *)mmap(NULL, 10000*sizeof(int),
00054 (PROT_READ | PROT_WRITE),
00055 MAP_FILE | MAP_SHARED,
00056 fd, 0);
00057
00058 if (buf == (int *)-1) exit(1);
00059
00060 buf[9124] = 55732;
00061
00062 while (count-- && buf[1763] != 7268) sleep(1);
00063
00064 unlink(DATA);
00065
00066 if (count > 0) exit(0);
00067 exit(1);
00068 }