compat_semctl.c revision 1.2
11.2Schristos/* $NetBSD: compat_semctl.c,v 1.2 2009/01/11 02:46:26 christos Exp $ */
21.1Schristos
31.1Schristos/*
41.1Schristos * Copyright (c) 1994, 1995 Christopher G. Demetriou
51.1Schristos * All rights reserved.
61.1Schristos *
71.1Schristos * Redistribution and use in source and binary forms, with or without
81.1Schristos * modification, are permitted provided that the following conditions
91.1Schristos * are met:
101.1Schristos * 1. Redistributions of source code must retain the above copyright
111.1Schristos *    notice, this list of conditions and the following disclaimer.
121.1Schristos * 2. Redistributions in binary form must reproduce the above copyright
131.1Schristos *    notice, this list of conditions and the following disclaimer in the
141.1Schristos *    documentation and/or other materials provided with the distribution.
151.1Schristos * 3. All advertising materials mentioning features or use of this software
161.1Schristos *    must display the following acknowledgement:
171.1Schristos *          This product includes software developed for the
181.1Schristos *          NetBSD Project.  See http://www.NetBSD.org/ for
191.1Schristos *          information about NetBSD.
201.1Schristos * 4. The name of the author may not be used to endorse or promote products
211.1Schristos *    derived from this software without specific prior written permission.
221.1Schristos *
231.1Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
241.1Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
251.1Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
261.1Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
271.1Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
281.1Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
291.1Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
301.1Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
311.1Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
321.1Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
331.1Schristos *
341.1Schristos * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
351.1Schristos */
361.1Schristos
371.1Schristos#include <sys/cdefs.h>
381.1Schristos#if defined(LIBC_SCCS) && !defined(lint)
391.2Schristos__RCSID("$NetBSD: compat_semctl.c,v 1.2 2009/01/11 02:46:26 christos Exp $");
401.1Schristos#endif /* LIBC_SCCS and not lint */
411.1Schristos
421.1Schristos#define __LIBC12_SOURCE__
431.1Schristos#include <sys/types.h>
441.1Schristos#include <sys/ipc.h>
451.1Schristos#include <sys/sem.h>
461.2Schristos#include <sys/null.h>
471.1Schristos#include <compat/sys/sem.h>
481.2Schristos#include <stdarg.h>
491.1Schristos
501.1Schristosint
511.2Schristossemctl(int semid, int semnum, int cmd, ...)
521.1Schristos{
531.2Schristos	va_list ap;
541.2Schristos	union __semun semun;
551.2Schristos	struct semid_ds ds;
561.2Schristos	struct semid_ds14 *ds14 = NULL;
571.2Schristos	int error;
581.2Schristos
591.2Schristos	va_start(ap, cmd);
601.2Schristos	switch (cmd) {
611.2Schristos	case IPC_SET:
621.2Schristos	case IPC_STAT:
631.2Schristos	case GETALL:
641.2Schristos	case SETVAL:
651.2Schristos	case SETALL:
661.2Schristos#ifdef __lint__
671.2Schristos		memcpy(&semun, &ap, sizeof(semun));
681.2Schristos#else
691.2Schristos		semun = va_arg(ap, union __semun);
701.2Schristos#endif
711.2Schristos	}
721.2Schristos	va_end(ap);
731.2Schristos
741.2Schristos	switch (cmd) {
751.2Schristos	case IPC_SET:
761.2Schristos	case IPC_STAT:
771.2Schristos		ds14 = (struct semid_ds14 *)(void *)semun.buf;
781.2Schristos		if (cmd == IPC_SET)
791.2Schristos			__semid_ds14_to_native(ds14, &ds);
801.2Schristos		semun.buf = &ds;
811.2Schristos		break;
821.2Schristos	}
831.2Schristos
841.2Schristos	error = __semctl50(semid, semnum, cmd, &semun);
851.2Schristos	switch (cmd) {
861.2Schristos	case IPC_SET:
871.2Schristos	case IPC_STAT:
881.2Schristos		semun.buf = (struct semid_ds *)(void *)ds14;
891.2Schristos		if (cmd == IPC_STAT && error == 0)
901.2Schristos			__native_to_semid_ds14(&ds, ds14);
911.2Schristos		break;
921.2Schristos	}
931.2Schristos	return error;
941.1Schristos}
95