compat_semctl.c revision 1.3
11.3Schristos/* $NetBSD: compat_semctl.c,v 1.3 2011/01/31 22:51:39 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.3Schristos__RCSID("$NetBSD: compat_semctl.c,v 1.3 2011/01/31 22:51:39 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.3Schristos	struct semid_ds14 *ds14;
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.3Schristos		break;
721.3Schristos	default:
731.3Schristos		break;
741.2Schristos	}
751.2Schristos	va_end(ap);
761.2Schristos
771.2Schristos	switch (cmd) {
781.2Schristos	case IPC_SET:
791.2Schristos	case IPC_STAT:
801.3Schristos		ds14 = (void *)semun.buf;
811.2Schristos		if (cmd == IPC_SET)
821.2Schristos			__semid_ds14_to_native(ds14, &ds);
831.2Schristos		semun.buf = &ds;
841.2Schristos		break;
851.3Schristos	default:
861.3Schristos		ds14 = NULL;
871.3Schristos		break;
881.2Schristos	}
891.2Schristos
901.2Schristos	error = __semctl50(semid, semnum, cmd, &semun);
911.3Schristos	if (error)
921.3Schristos		return error;
931.3Schristos
941.3Schristos	if (cmd == IPC_STAT)
951.3Schristos		__native_to_semid_ds14(&ds, ds14);
961.3Schristos	return 0;
971.1Schristos}
98