semctl.c revision 1.13
11.13Schristos/*	$NetBSD: semctl.c,v 1.13 2009/01/11 02:46:30 christos 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.13Schristos__RCSID("$NetBSD: semctl.c,v 1.13 2009/01/11 02:46:30 christos 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.13Schristos
411.13Schristos/* The kernel version [... == union semun *] */
421.13Schristosint ____semctl50(int, int, int, ...);
431.1Scgd
441.9Swizint
451.13Schristossemctl(int semid, int semnum, int cmd, ...)
461.1Scgd{
471.13Schristos	va_list ap;
481.13Schristos	union __semun semun;
491.13Schristos
501.13Schristos	va_start(ap, cmd);
511.13Schristos	switch (cmd) {
521.13Schristos	case IPC_SET:
531.13Schristos	case IPC_STAT:
541.13Schristos	case GETALL:
551.13Schristos	case SETVAL:
561.13Schristos	case SETALL:
571.13Schristos#ifdef __lint__
581.13Schristos		memcpy(&semun, &ap, sizeof(semun));
591.13Schristos#else
601.13Schristos		semun = va_arg(ap, union __semun);
611.13Schristos#endif
621.13Schristos	}
631.13Schristos	va_end(ap);
641.13Schristos	return ____semctl50(semid, semnum, cmd, &semun);
651.1Scgd}
66