1*68179c3dSjoerg /* $NetBSD: compat_semctl.c,v 1.6 2015/01/29 20:44:38 joerg Exp $ */
25b84b398Schristos
35b84b398Schristos /*
45b84b398Schristos * Copyright (c) 1994, 1995 Christopher G. Demetriou
55b84b398Schristos * All rights reserved.
65b84b398Schristos *
75b84b398Schristos * Redistribution and use in source and binary forms, with or without
85b84b398Schristos * modification, are permitted provided that the following conditions
95b84b398Schristos * are met:
105b84b398Schristos * 1. Redistributions of source code must retain the above copyright
115b84b398Schristos * notice, this list of conditions and the following disclaimer.
125b84b398Schristos * 2. Redistributions in binary form must reproduce the above copyright
135b84b398Schristos * notice, this list of conditions and the following disclaimer in the
145b84b398Schristos * documentation and/or other materials provided with the distribution.
155b84b398Schristos * 3. All advertising materials mentioning features or use of this software
165b84b398Schristos * must display the following acknowledgement:
175b84b398Schristos * This product includes software developed for the
185b84b398Schristos * NetBSD Project. See http://www.NetBSD.org/ for
195b84b398Schristos * information about NetBSD.
205b84b398Schristos * 4. The name of the author may not be used to endorse or promote products
215b84b398Schristos * derived from this software without specific prior written permission.
225b84b398Schristos *
235b84b398Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
245b84b398Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
255b84b398Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
265b84b398Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
275b84b398Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
285b84b398Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
295b84b398Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
305b84b398Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
315b84b398Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
325b84b398Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
335b84b398Schristos *
345b84b398Schristos * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
355b84b398Schristos */
365b84b398Schristos
375b84b398Schristos #include <sys/cdefs.h>
385b84b398Schristos #if defined(LIBC_SCCS) && !defined(lint)
39*68179c3dSjoerg __RCSID("$NetBSD: compat_semctl.c,v 1.6 2015/01/29 20:44:38 joerg Exp $");
405b84b398Schristos #endif /* LIBC_SCCS and not lint */
415b84b398Schristos
425b84b398Schristos #define __LIBC12_SOURCE__
435b84b398Schristos #include <sys/types.h>
445b84b398Schristos #include <sys/ipc.h>
455b84b398Schristos #include <sys/sem.h>
46461a86f9Schristos #include <sys/null.h>
475b84b398Schristos #include <compat/sys/sem.h>
48461a86f9Schristos #include <stdarg.h>
4976ef5347Sjoerg #ifdef __lint__
5076ef5347Sjoerg #include <string.h>
5176ef5347Sjoerg #endif
525b84b398Schristos
535b84b398Schristos int
semctl(int semid,int semnum,int cmd,...)54461a86f9Schristos semctl(int semid, int semnum, int cmd, ...)
555b84b398Schristos {
56461a86f9Schristos va_list ap;
57461a86f9Schristos union __semun semun;
58461a86f9Schristos struct semid_ds ds;
59bcb5ce20Schristos struct semid_ds14 *ds14;
60461a86f9Schristos int error;
61461a86f9Schristos
62461a86f9Schristos va_start(ap, cmd);
63461a86f9Schristos switch (cmd) {
64461a86f9Schristos case IPC_SET:
65461a86f9Schristos case IPC_STAT:
66461a86f9Schristos case GETALL:
67461a86f9Schristos case SETVAL:
68461a86f9Schristos case SETALL:
69461a86f9Schristos #ifdef __lint__
70461a86f9Schristos memcpy(&semun, &ap, sizeof(semun));
71461a86f9Schristos #else
72461a86f9Schristos semun = va_arg(ap, union __semun);
73461a86f9Schristos #endif
74bcb5ce20Schristos break;
75bcb5ce20Schristos default:
76bcb5ce20Schristos break;
77461a86f9Schristos }
78461a86f9Schristos va_end(ap);
79461a86f9Schristos
80461a86f9Schristos switch (cmd) {
81461a86f9Schristos case IPC_SET:
82461a86f9Schristos case IPC_STAT:
83bcb5ce20Schristos ds14 = (void *)semun.buf;
84461a86f9Schristos if (cmd == IPC_SET)
85461a86f9Schristos __semid_ds14_to_native(ds14, &ds);
86461a86f9Schristos semun.buf = &ds;
87461a86f9Schristos break;
88bcb5ce20Schristos default:
89bcb5ce20Schristos ds14 = NULL;
90bcb5ce20Schristos break;
91461a86f9Schristos }
92461a86f9Schristos
93461a86f9Schristos error = __semctl50(semid, semnum, cmd, &semun);
94bcb5ce20Schristos if (error)
95461a86f9Schristos return error;
96bcb5ce20Schristos
97bcb5ce20Schristos if (cmd == IPC_STAT)
98bcb5ce20Schristos __native_to_semid_ds14(&ds, ds14);
99bcb5ce20Schristos return 0;
1005b84b398Schristos }
101