compat_semctl.c revision 1.6
11.6Sjoerg/* $NetBSD: compat_semctl.c,v 1.6 2015/01/29 20:44:38 joerg 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.6Sjoerg__RCSID("$NetBSD: compat_semctl.c,v 1.6 2015/01/29 20:44:38 joerg 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.4Sjoerg#ifdef __lint__
501.4Sjoerg#include <string.h>
511.4Sjoerg#endif
521.1Schristos
531.1Schristosint
541.2Schristossemctl(int semid, int semnum, int cmd, ...)
551.1Schristos{
561.2Schristos	va_list ap;
571.2Schristos	union __semun semun;
581.2Schristos	struct semid_ds ds;
591.3Schristos	struct semid_ds14 *ds14;
601.2Schristos	int error;
611.2Schristos
621.2Schristos	va_start(ap, cmd);
631.2Schristos	switch (cmd) {
641.2Schristos	case IPC_SET:
651.2Schristos	case IPC_STAT:
661.2Schristos	case GETALL:
671.2Schristos	case SETVAL:
681.2Schristos	case SETALL:
691.2Schristos#ifdef __lint__
701.2Schristos		memcpy(&semun, &ap, sizeof(semun));
711.2Schristos#else
721.2Schristos		semun = va_arg(ap, union __semun);
731.2Schristos#endif
741.3Schristos		break;
751.3Schristos	default:
761.3Schristos		break;
771.2Schristos	}
781.2Schristos	va_end(ap);
791.2Schristos
801.2Schristos	switch (cmd) {
811.2Schristos	case IPC_SET:
821.2Schristos	case IPC_STAT:
831.3Schristos		ds14 = (void *)semun.buf;
841.2Schristos		if (cmd == IPC_SET)
851.2Schristos			__semid_ds14_to_native(ds14, &ds);
861.2Schristos		semun.buf = &ds;
871.2Schristos		break;
881.3Schristos	default:
891.3Schristos		ds14 = NULL;
901.3Schristos		break;
911.2Schristos	}
921.2Schristos
931.2Schristos	error = __semctl50(semid, semnum, cmd, &semun);
941.3Schristos	if (error)
951.3Schristos		return error;
961.3Schristos
971.3Schristos	if (cmd == IPC_STAT)
981.3Schristos		__native_to_semid_ds14(&ds, ds14);
991.3Schristos	return 0;
1001.1Schristos}
101