]> granicus.if.org Git - strace/blob - tests/shmxt.c
Mpersify RTC_* ioctl parser
[strace] / tests / shmxt.c
1 #include "tests.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/shm.h>
5
6 static int id = -1;
7
8 static void
9 cleanup(void)
10 {
11         shmctl(id, IPC_RMID, NULL);
12         id = -1;
13 }
14
15 #ifdef __alpha__
16 # define SHMAT "osf_shmat"
17 #else
18 # define SHMAT "shmat"
19 #endif
20
21 int
22 main(void)
23 {
24         id = shmget(IPC_PRIVATE, 1, 0600);
25         if (id < 0)
26                 perror_msg_and_skip("shmget");
27         atexit(cleanup);
28
29         shmat(id, NULL, SHM_REMAP);
30         printf("%s(%d, NULL, SHM_REMAP) = -1 %s (%m)\n",
31                SHMAT, id, errno2name());
32
33         void *shmaddr = shmat(id, NULL, SHM_RDONLY);
34         if (shmaddr == (void *)(-1))
35                 perror_msg_and_skip("shmat SHM_RDONLY");
36         printf("%s(%d, NULL, SHM_RDONLY) = %p\n", SHMAT, id, shmaddr);
37
38         if (shmdt(shmaddr))
39                 perror_msg_and_skip("shmdt");
40         printf("shmdt(%p) = 0\n", shmaddr);
41
42         ++shmaddr;
43         void *shmaddr2 = shmat(id, shmaddr, SHM_RND);
44         if (shmaddr2 == (void *)(-1))
45                 printf("%s(%d, %p, SHM_RND) = -1 %s (%m)\n",
46                        SHMAT, id, shmaddr, errno2name());
47         else
48                 printf("%s(%d, %p, SHM_RND) = %p\n",
49                        SHMAT, id, shmaddr, shmaddr2);
50
51         puts("+++ exited with 0 +++");
52         return 0;
53 }