Merge commit '281819e5f8b19cd8627541a22d261906fd190276' into merges
[unleashed.git] / usr / src / lib / libc / port / sys / msgsys.c
blob997c14fee60016a3f260eae51de0e0b0f2859203
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #pragma weak _msgctl = msgctl
33 #pragma weak _msgget = msgget
34 #pragma weak _msgids = msgids
35 #pragma weak _msgsnap = msgsnap
37 #include "lint.h"
38 #include <sys/types.h>
39 #include <sys/ipc.h>
40 #include <sys/ipc_impl.h>
41 #include <sys/msg.h>
42 #include <sys/msg_impl.h>
43 #include <sys/syscall.h>
44 #include <errno.h>
45 #include <limits.h>
47 int
48 msgget(key_t key, int msgflg)
50 return (syscall(SYS_msgsys, MSGGET, key, msgflg));
53 int
54 msgctl(int msqid, int cmd, struct msqid_ds *buf)
56 if (cmd == IPC_SET64 || cmd == IPC_STAT64) {
57 (void) __set_errno(EINVAL);
58 return (-1);
61 return (syscall(SYS_msgsys, MSGCTL, msqid, cmd, buf));
64 int
65 msgctl64(int msqid, int cmd, struct msqid_ds64 *buf)
67 if (cmd != IPC_SET64 && cmd != IPC_STAT64) {
68 (void) __set_errno(EINVAL);
69 return (-1);
72 return (syscall(SYS_msgsys, MSGCTL, msqid, cmd, buf));
75 ssize_t
76 __msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
78 if (msgsz > INT_MAX) {
79 sysret_t rval;
80 int error;
83 * We have to use __systemcall here because in the
84 * 64-bit case, we need to return a long, while
85 * syscall() is doomed to return an int
87 error = __systemcall(&rval, SYS_msgsys, MSGRCV, msqid,
88 msgp, msgsz, msgtyp, msgflg);
89 if (error)
90 (void) __set_errno(error);
91 return ((ssize_t)rval.sys_rval1);
93 return ((ssize_t)syscall(SYS_msgsys, MSGRCV, msqid,
94 msgp, msgsz, msgtyp, msgflg));
97 int
98 __msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
100 if (msgsz > INT_MAX) {
101 sysret_t rval;
102 int error;
104 error = __systemcall(&rval, SYS_msgsys, MSGSND, msqid,
105 msgp, msgsz, msgflg);
106 if (error)
107 (void) __set_errno(error);
108 return ((int)rval.sys_rval1);
110 return (syscall(SYS_msgsys, MSGSND, msqid, msgp, msgsz, msgflg));
114 msgids(int *buf, uint_t nids, uint_t *pnids)
116 return (syscall(SYS_msgsys, MSGIDS, buf, nids, pnids));
120 msgsnap(int msqid, void *buf, size_t bufsz, long msgtyp)
122 return (syscall(SYS_msgsys, MSGSNAP, msqid, buf, bufsz, msgtyp));