]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/unit_tests/semctl_test_8534495_src/semctl_test_8534495.c
5c25f55815f68089b2555f0fec4ebdb91ad50473
[apple/xnu.git] / tools / tests / unit_tests / semctl_test_8534495_src / semctl_test_8534495.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/ipc.h>
4 #include <sys/sem.h>
5 #include <sys/stat.h>
6
7 int main(void) {
8 key_t key;
9
10 if ((key = ftok(".", 1)) == (key_t)-1) {
11 perror("ftok");
12 exit(EXIT_FAILURE);
13 }
14
15 int semid;
16 if ((semid = semget(key, 1, IPC_CREAT | S_IRUSR | S_IWUSR)) == -1) {
17 perror("semget");
18 exit(EXIT_FAILURE);
19 }
20
21 union semun arg;
22
23 /* Test for sem value > SEMVMX */
24 arg.val = 32768;
25 if (semctl(semid, 0, SETVAL, arg) == 0) {
26 printf("semctl should have failed for SETVAL 32768\n");
27 exit(EXIT_FAILURE);
28 }
29
30 /* Test for sem value < 0 */
31 arg.val = -1;
32 if (semctl(semid, 0, SETVAL, arg) == 0) {
33 printf("semctl should have failed for SETVAL -1\n");
34 exit(EXIT_FAILURE);
35 }
36
37 return 0;
38 }