semctl.c revision 1.18
11.18Sjoerg/*	$NetBSD: semctl.c,v 1.18 2015/01/29 20:44:38 joerg Exp $	*/
21.5Sthorpej
31.13Schristos/*-
41.13Schristos * Copyright (c) 2000 The NetBSD Foundation, Inc.
51.3Scgd * All rights reserved.
61.13Schristos *
71.13Schristos * This code is derived from software contributed to The NetBSD Foundation
81.13Schristos * by Christos Zoulas.
91.13Schristos *
101.3Scgd * Redistribution and use in source and binary forms, with or without
111.3Scgd * modification, are permitted provided that the following conditions
121.3Scgd * are met:
131.3Scgd * 1. Redistributions of source code must retain the above copyright
141.3Scgd *    notice, this list of conditions and the following disclaimer.
151.3Scgd * 2. Redistributions in binary form must reproduce the above copyright
161.3Scgd *    notice, this list of conditions and the following disclaimer in the
171.3Scgd *    documentation and/or other materials provided with the distribution.
181.13Schristos *
191.13Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.13Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.13Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.13Schristos * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.13Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.13Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.13Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.13Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.13Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.13Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.13Schristos * POSSIBILITY OF SUCH DAMAGE.
301.3Scgd */
311.4Schristos#include <sys/cdefs.h>
321.3Scgd#if defined(LIBC_SCCS) && !defined(lint)
331.18Sjoerg__RCSID("$NetBSD: semctl.c,v 1.18 2015/01/29 20:44:38 joerg Exp $");
341.3Scgd#endif /* LIBC_SCCS and not lint */
351.1Scgd
361.1Scgd#include <sys/types.h>
371.1Scgd#include <sys/ipc.h>
381.1Scgd#include <sys/sem.h>
391.13Schristos#include <stdarg.h>
401.16Sjoerg#ifdef __lint__
411.16Sjoerg#include <string.h>
421.16Sjoerg#endif
431.13Schristos
441.13Schristos/* The kernel version [... == union semun *] */
451.13Schristosint ____semctl50(int, int, int, ...);
461.1Scgd
471.9Swizint
481.13Schristossemctl(int semid, int semnum, int cmd, ...)
491.1Scgd{
501.13Schristos	va_list ap;
511.13Schristos	union __semun semun;
521.13Schristos
531.13Schristos	va_start(ap, cmd);
541.13Schristos	switch (cmd) {
551.13Schristos	case IPC_SET:
561.13Schristos	case IPC_STAT:
571.13Schristos	case GETALL:
581.13Schristos	case SETVAL:
591.13Schristos	case SETALL:
601.13Schristos#ifdef __lint__
611.13Schristos		memcpy(&semun, &ap, sizeof(semun));
621.13Schristos#else
631.13Schristos		semun = va_arg(ap, union __semun);
641.13Schristos#endif
651.13Schristos	}
661.13Schristos	va_end(ap);
671.13Schristos	return ____semctl50(semid, semnum, cmd, &semun);
681.1Scgd}
69