xref: /netbsd-src/lib/libc/sys/semctl.c (revision 68179c3df2d966fb85732fde63852e449a8dd3ab)
1*68179c3dSjoerg /*	$NetBSD: semctl.c,v 1.18 2015/01/29 20:44:38 joerg Exp $	*/
2584a4c6aSchristos 
3584a4c6aSchristos /*-
4584a4c6aSchristos  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5584a4c6aSchristos  * All rights reserved.
6584a4c6aSchristos  *
7584a4c6aSchristos  * This code is derived from software contributed to The NetBSD Foundation
8584a4c6aSchristos  * by Christos Zoulas.
9584a4c6aSchristos  *
10584a4c6aSchristos  * Redistribution and use in source and binary forms, with or without
11584a4c6aSchristos  * modification, are permitted provided that the following conditions
12584a4c6aSchristos  * are met:
13584a4c6aSchristos  * 1. Redistributions of source code must retain the above copyright
14584a4c6aSchristos  *    notice, this list of conditions and the following disclaimer.
15584a4c6aSchristos  * 2. Redistributions in binary form must reproduce the above copyright
16584a4c6aSchristos  *    notice, this list of conditions and the following disclaimer in the
17584a4c6aSchristos  *    documentation and/or other materials provided with the distribution.
18584a4c6aSchristos  *
19584a4c6aSchristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20584a4c6aSchristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21584a4c6aSchristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22584a4c6aSchristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23584a4c6aSchristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24584a4c6aSchristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25584a4c6aSchristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26584a4c6aSchristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27584a4c6aSchristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28584a4c6aSchristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29584a4c6aSchristos  * POSSIBILITY OF SUCH DAMAGE.
30584a4c6aSchristos  */
31584a4c6aSchristos #include <sys/cdefs.h>
32584a4c6aSchristos #if defined(LIBC_SCCS) && !defined(lint)
33*68179c3dSjoerg __RCSID("$NetBSD: semctl.c,v 1.18 2015/01/29 20:44:38 joerg Exp $");
34584a4c6aSchristos #endif /* LIBC_SCCS and not lint */
35584a4c6aSchristos 
36584a4c6aSchristos #include <sys/types.h>
37584a4c6aSchristos #include <sys/ipc.h>
38584a4c6aSchristos #include <sys/sem.h>
39584a4c6aSchristos #include <stdarg.h>
4076ef5347Sjoerg #ifdef __lint__
4176ef5347Sjoerg #include <string.h>
4276ef5347Sjoerg #endif
43584a4c6aSchristos 
44584a4c6aSchristos /* The kernel version [... == union semun *] */
45584a4c6aSchristos int ____semctl50(int, int, int, ...);
46584a4c6aSchristos 
47584a4c6aSchristos int
semctl(int semid,int semnum,int cmd,...)48584a4c6aSchristos semctl(int semid, int semnum, int cmd, ...)
49584a4c6aSchristos {
50584a4c6aSchristos 	va_list ap;
51584a4c6aSchristos 	union __semun semun;
52584a4c6aSchristos 
53584a4c6aSchristos 	va_start(ap, cmd);
54584a4c6aSchristos 	switch (cmd) {
55584a4c6aSchristos 	case IPC_SET:
56584a4c6aSchristos 	case IPC_STAT:
57584a4c6aSchristos 	case GETALL:
58584a4c6aSchristos 	case SETVAL:
59584a4c6aSchristos 	case SETALL:
60584a4c6aSchristos #ifdef __lint__
61584a4c6aSchristos 		memcpy(&semun, &ap, sizeof(semun));
62584a4c6aSchristos #else
63584a4c6aSchristos 		semun = va_arg(ap, union __semun);
64584a4c6aSchristos #endif
65584a4c6aSchristos 	}
66584a4c6aSchristos 	va_end(ap);
67584a4c6aSchristos 	return ____semctl50(semid, semnum, cmd, &semun);
68584a4c6aSchristos }
69