xref: /openbsd-src/lib/libc/sys/semctl.c (revision 16ac854bbf7bcdea047fcbe608a2563173d99268)
1*16ac854bSguenther /*	$OpenBSD: semctl.c,v 1.9 2015/09/14 12:08:22 guenther Exp $ */
2df930be7Sderaadt /*
3df930be7Sderaadt  * Copyright (c) 1994, 1995 Christopher G. Demetriou
4df930be7Sderaadt  * All rights reserved.
5df930be7Sderaadt  *
6df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
7df930be7Sderaadt  * modification, are permitted provided that the following conditions
8df930be7Sderaadt  * are met:
9df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
10df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
11df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
12df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
13df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
14df930be7Sderaadt  * 3. All advertising materials mentioning features or use of this software
15df930be7Sderaadt  *    must display the following acknowledgement:
16df930be7Sderaadt  *	This product includes software developed by Christopher G. Demetriou
17df930be7Sderaadt  *	for the NetBSD Project.
18df930be7Sderaadt  * 4. The name of the author may not be used to endorse or promote products
19df930be7Sderaadt  *    derived from this software without specific prior written permission
20df930be7Sderaadt  *
21df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22df930be7Sderaadt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23df930be7Sderaadt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24df930be7Sderaadt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25df930be7Sderaadt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26df930be7Sderaadt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27df930be7Sderaadt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28df930be7Sderaadt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29df930be7Sderaadt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30df930be7Sderaadt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31df930be7Sderaadt  */
32df930be7Sderaadt 
33df930be7Sderaadt #include <sys/sem.h>
3484dc39afSderaadt #include <stdarg.h>
3584dc39afSderaadt #include <stdlib.h>
3684dc39afSderaadt 
37*16ac854bSguenther int
semctl(int semid,int semnum,int cmd,...)38*16ac854bSguenther semctl(int semid, int semnum, int cmd, ...)
39df930be7Sderaadt {
4084dc39afSderaadt 	va_list ap;
4184dc39afSderaadt 	union semun semun;
4284dc39afSderaadt 	union semun *semun_ptr = NULL;
43e7beb4a7Smillert 
4484dc39afSderaadt 	va_start(ap, cmd);
4584dc39afSderaadt 	if (cmd == IPC_SET || cmd == IPC_STAT || cmd == GETALL ||
4684dc39afSderaadt 	    cmd == SETVAL || cmd == SETALL) {
4784dc39afSderaadt 		semun = va_arg(ap, union semun);
4884dc39afSderaadt 		semun_ptr = &semun;
4984dc39afSderaadt 	}
5084dc39afSderaadt 	va_end(ap);
5184dc39afSderaadt 
5284dc39afSderaadt 	return (__semctl(semid, semnum, cmd, semun_ptr));
53df930be7Sderaadt }
54