xref: /freebsd/lib/libc/gen/semctl.c (revision daf1cffce2e07931f27c6c6998652e90df6ba87e)
1 #include <sys/types.h>
2 #include <sys/ipc.h>
3 #include <sys/sem.h>
4 #if __STDC__
5 #include <stdarg.h>
6 #else
7 #include <varargs.h>
8 #endif
9 #include <stdlib.h>
10 
11 #if __STDC__
12 int semctl(int semid, int semnum, int cmd, ...)
13 #else
14 int semctl(semid, semnum, cmd, va_alist)
15 	int semid, semnum;
16 	int cmd;
17 	va_dcl
18 #endif
19 {
20 	va_list ap;
21 	union semun semun;
22 	union semun *semun_ptr;
23 #if __STDC__
24 	va_start(ap, cmd);
25 #else
26 	va_start(ap);
27 #endif
28 	if (cmd == IPC_SET || cmd == IPC_STAT || cmd == GETALL
29 	    || cmd == SETVAL || cmd == SETALL) {
30 		semun = va_arg(ap, union semun);
31 		semun_ptr = &semun;
32 	} else {
33 		semun_ptr = NULL;
34 	}
35 	va_end(ap);
36 
37 #ifdef	__NETBSD_SYSCALLS
38 	return (__semctl(semid, semnum, cmd, semun_ptr));
39 #else
40 	return (semsys(0, semid, semnum, cmd, semun_ptr));
41 #endif
42 }
43