1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984 AT&T */ 28 /* All Rights Reserved */ 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <sys/syscall.h> 33 #include <stdarg.h> 34 #include <sys/types.h> 35 #include <sys/ipc.h> 36 #include <sys/msg.h> 37 38 39 /* msgsys dispatch argument */ 40 #define MSGGET 0 41 #define MSGCTL 1 42 #define MSGRCV 2 43 #define MSGSND 3 44 45 int 46 msgget(key_t key, int msgflg) 47 { 48 return (_syscall(SYS_msgsys, MSGGET, key, msgflg)); 49 } 50 51 int 52 msgctl(int msqid, int cmd, struct msqid_ds *buf) 53 { 54 return (_syscall(SYS_msgsys, MSGCTL, msqid, cmd, buf)); 55 } 56 57 int 58 msgrcv(int msqid, struct msgbuf *msgp, int msgsz, long msgtyp, int msgflg) 59 { 60 return (_syscall(SYS_msgsys, MSGRCV, 61 msqid, msgp, msgsz, msgtyp, msgflg)); 62 } 63 64 int 65 msgsnd(int msqid, struct msgbuf *msgp, int msgsz, int msgflg) 66 { 67 return (_syscall(SYS_msgsys, MSGSND, 68 msqid, msgp, msgsz, msgflg)); 69 } 70 71 int 72 msgsys(int sysnum, ...) 73 { 74 va_list ap; 75 key_t key; 76 int msgflg; 77 int msgflag; 78 int msqid, cmd; 79 struct msqid_ds *buf; 80 struct msgbuf *msgp; 81 int msgsz; 82 long msgtyp; 83 84 va_start(ap, sysnum); 85 switch (sysnum) { 86 case MSGGET: 87 key = va_arg(ap, key_t); 88 msgflag = va_arg(ap, int); 89 va_end(ap); 90 return (msgget(key, msgflag)); 91 case MSGCTL: 92 msqid = va_arg(ap, int); 93 cmd = va_arg(ap, int); 94 buf = va_arg(ap, struct msqid_ds *); 95 va_end(ap); 96 return (msgctl(msqid, cmd, buf)); 97 case MSGRCV: 98 msqid = va_arg(ap, int); 99 msgp = va_arg(ap, struct msgbuf *); 100 msgsz = va_arg(ap, int); 101 msgtyp = va_arg(ap, long); 102 msgflg = va_arg(ap, int); 103 va_end(ap); 104 return (msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)); 105 case MSGSND: 106 msqid = va_arg(ap, int); 107 msgp = va_arg(ap, struct msgbuf *); 108 msgsz = va_arg(ap, int); 109 msgflg = va_arg(ap, int); 110 va_end(ap); 111 return (msgsnd(msqid, msgp, msgsz, msgflg)); 112 } 113 va_end(ap); 114 return (-1); 115 } 116