xref: /titanic_41/usr/src/lib/libbc/libc/sys/common/msgsys.c (revision f29fbe76ce646ba8bcf62627d89087d5f02c62a8)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1993 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	<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, msqid, msgp, msgsz, msgtyp, msgflg));
61 }
62 
63 int
64 msgsnd(int msqid, struct msgbuf *msgp, int msgsz, int msgflg)
65 {
66 	return (_syscall(SYS_msgsys, MSGSND, msqid, msgp, msgsz, msgflg));
67 }
68 
69 int
70 msgsys(int sysnum, ...)
71 {
72 	va_list ap;
73 	key_t key;
74 	int msgflg;
75 	int msgflag;
76 	int msqid, cmd;
77 	struct msqid_ds *buf;
78 	struct msgbuf *msgp;
79 	int msgsz;
80 	long msgtyp;
81 
82 
83 	va_start(ap, sysnum);
84 	switch (sysnum) {
85 	case MSGGET:
86 		key=va_arg(ap, key_t);
87 		msgflag=va_arg(ap, int);
88 		va_end(ap);
89 		return (msgget(key, msgflag));
90 	case MSGCTL:
91 		msqid=va_arg(ap, int);
92 		cmd=va_arg(ap, int);
93 		buf=va_arg(ap, struct msqid_ds *);
94 		va_end(ap);
95 		return (msgctl(msqid, cmd, buf));
96 	case MSGRCV:
97 		msqid=va_arg(ap, int);
98 		msgp=va_arg(ap, struct msgbuf *);
99 		msgsz=va_arg(ap, int);
100 		msgtyp=va_arg(ap, long);
101 		msgflg=va_arg(ap, int);
102 		va_end(ap);
103 		return (msgrcv(msqid, msgp, msgsz, msgtyp, msgflg));
104 	case MSGSND:
105 		msqid=va_arg(ap, int);
106 		msgp=va_arg(ap, struct msgbuf *);
107 		msgsz=va_arg(ap, int);
108 		msgflg=va_arg(ap, int);
109 		va_end(ap);
110 		return (msgsnd(msqid, msgp, msgsz, msgflg));
111 	}
112 	va_end(ap);
113 	return (-1);
114 }
115