smbd: Remove get_Protocol()
[Samba.git] / lib / replace / tests / shared_mmap.c
blob9d6e3fc95aa5d0981df1530582236ba826d1a432
1 /* this tests whether we can use a shared writeable mmap on a file -
2 as needed for the mmap variant of FAST_SHARE_MODES */
4 #if defined(HAVE_UNISTD_H)
5 #include <unistd.h>
6 #endif
7 #ifdef HAVE_STDLIB_H
8 #include <stdlib.h>
9 #endif
10 #include <sys/mman.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
15 #define DATA "conftest.mmap"
17 #ifndef MAP_FILE
18 #define MAP_FILE 0
19 #endif
21 int main(void)
23 int *buf;
24 int i;
25 int fd = open(DATA,O_RDWR|O_CREAT|O_TRUNC,0666);
26 int count=7;
28 if (fd == -1) exit(1);
30 for (i=0;i<10000;i++) {
31 write(fd,&i,sizeof(i));
34 close(fd);
36 if (fork() == 0) {
37 fd = open(DATA,O_RDWR);
38 if (fd == -1) exit(1);
40 buf = (int *)mmap(NULL, 10000*sizeof(int),
41 (PROT_READ | PROT_WRITE),
42 MAP_FILE | MAP_SHARED,
43 fd, 0);
45 while (count-- && buf[9124] != 55732) sleep(1);
47 if (count <= 0) exit(1);
49 buf[1763] = 7268;
50 exit(0);
53 fd = open(DATA,O_RDWR);
54 if (fd == -1) exit(1);
56 buf = (int *)mmap(NULL, 10000*sizeof(int),
57 (PROT_READ | PROT_WRITE),
58 MAP_FILE | MAP_SHARED,
59 fd, 0);
61 if (buf == (int *)-1) exit(1);
63 buf[9124] = 55732;
65 while (count-- && buf[1763] != 7268) sleep(1);
67 unlink(DATA);
69 if (count > 0) exit(0);
70 exit(1);