xref: /minix3/lib/libc/compat/sys/compat_semctl.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $NetBSD: compat_semctl.c,v 1.6 2015/01/29 20:44:38 joerg Exp $ */
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /*
42fe8fb19SBen Gras  * Copyright (c) 1994, 1995 Christopher G. Demetriou
52fe8fb19SBen Gras  * All rights reserved.
62fe8fb19SBen Gras  *
72fe8fb19SBen Gras  * Redistribution and use in source and binary forms, with or without
82fe8fb19SBen Gras  * modification, are permitted provided that the following conditions
92fe8fb19SBen Gras  * are met:
102fe8fb19SBen Gras  * 1. Redistributions of source code must retain the above copyright
112fe8fb19SBen Gras  *    notice, this list of conditions and the following disclaimer.
122fe8fb19SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
132fe8fb19SBen Gras  *    notice, this list of conditions and the following disclaimer in the
142fe8fb19SBen Gras  *    documentation and/or other materials provided with the distribution.
152fe8fb19SBen Gras  * 3. All advertising materials mentioning features or use of this software
162fe8fb19SBen Gras  *    must display the following acknowledgement:
172fe8fb19SBen Gras  *          This product includes software developed for the
182fe8fb19SBen Gras  *          NetBSD Project.  See http://www.NetBSD.org/ for
192fe8fb19SBen Gras  *          information about NetBSD.
202fe8fb19SBen Gras  * 4. The name of the author may not be used to endorse or promote products
212fe8fb19SBen Gras  *    derived from this software without specific prior written permission.
222fe8fb19SBen Gras  *
232fe8fb19SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
242fe8fb19SBen Gras  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
252fe8fb19SBen Gras  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
262fe8fb19SBen Gras  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
272fe8fb19SBen Gras  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
282fe8fb19SBen Gras  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
292fe8fb19SBen Gras  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
302fe8fb19SBen Gras  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
312fe8fb19SBen Gras  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
322fe8fb19SBen Gras  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
332fe8fb19SBen Gras  *
342fe8fb19SBen Gras  * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
352fe8fb19SBen Gras  */
362fe8fb19SBen Gras 
372fe8fb19SBen Gras #include <sys/cdefs.h>
382fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
39*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: compat_semctl.c,v 1.6 2015/01/29 20:44:38 joerg Exp $");
402fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
412fe8fb19SBen Gras 
422fe8fb19SBen Gras #define __LIBC12_SOURCE__
432fe8fb19SBen Gras #include <sys/types.h>
442fe8fb19SBen Gras #include <sys/ipc.h>
452fe8fb19SBen Gras #include <sys/sem.h>
462fe8fb19SBen Gras #include <sys/null.h>
472fe8fb19SBen Gras #include <compat/sys/sem.h>
482fe8fb19SBen Gras #include <stdarg.h>
49*0a6a1f1dSLionel Sambuc #ifdef __lint__
50*0a6a1f1dSLionel Sambuc #include <string.h>
51*0a6a1f1dSLionel Sambuc #endif
522fe8fb19SBen Gras 
532fe8fb19SBen Gras int
semctl(int semid,int semnum,int cmd,...)542fe8fb19SBen Gras semctl(int semid, int semnum, int cmd, ...)
552fe8fb19SBen Gras {
562fe8fb19SBen Gras 	va_list ap;
572fe8fb19SBen Gras 	union __semun semun;
582fe8fb19SBen Gras 	struct semid_ds ds;
59f14fb602SLionel Sambuc 	struct semid_ds14 *ds14;
602fe8fb19SBen Gras 	int error;
612fe8fb19SBen Gras 
622fe8fb19SBen Gras 	va_start(ap, cmd);
632fe8fb19SBen Gras 	switch (cmd) {
642fe8fb19SBen Gras 	case IPC_SET:
652fe8fb19SBen Gras 	case IPC_STAT:
662fe8fb19SBen Gras 	case GETALL:
672fe8fb19SBen Gras 	case SETVAL:
682fe8fb19SBen Gras 	case SETALL:
692fe8fb19SBen Gras #ifdef __lint__
702fe8fb19SBen Gras 		memcpy(&semun, &ap, sizeof(semun));
712fe8fb19SBen Gras #else
722fe8fb19SBen Gras 		semun = va_arg(ap, union __semun);
732fe8fb19SBen Gras #endif
74f14fb602SLionel Sambuc 		break;
75f14fb602SLionel Sambuc 	default:
76f14fb602SLionel Sambuc 		break;
772fe8fb19SBen Gras 	}
782fe8fb19SBen Gras 	va_end(ap);
792fe8fb19SBen Gras 
802fe8fb19SBen Gras 	switch (cmd) {
812fe8fb19SBen Gras 	case IPC_SET:
822fe8fb19SBen Gras 	case IPC_STAT:
83f14fb602SLionel Sambuc 		ds14 = (void *)semun.buf;
842fe8fb19SBen Gras 		if (cmd == IPC_SET)
852fe8fb19SBen Gras 			__semid_ds14_to_native(ds14, &ds);
862fe8fb19SBen Gras 		semun.buf = &ds;
872fe8fb19SBen Gras 		break;
88f14fb602SLionel Sambuc 	default:
89f14fb602SLionel Sambuc 		ds14 = NULL;
90f14fb602SLionel Sambuc 		break;
912fe8fb19SBen Gras 	}
922fe8fb19SBen Gras 
932fe8fb19SBen Gras 	error = __semctl50(semid, semnum, cmd, &semun);
94f14fb602SLionel Sambuc 	if (error)
952fe8fb19SBen Gras 		return error;
96f14fb602SLionel Sambuc 
97f14fb602SLionel Sambuc 	if (cmd == IPC_STAT)
98f14fb602SLionel Sambuc 		__native_to_semid_ds14(&ds, ds14);
99f14fb602SLionel Sambuc 	return 0;
1002fe8fb19SBen Gras }
101