Add missing export of fallocate64 on 32-bit platforms.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / msgctl.c
blobafecc49dd74219d35c298aa8ea91b38caf265c4b
1 /* Copyright (C) 1995,1997,1998,2000,2004,2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <sys/msg.h>
22 #include <ipc_priv.h>
24 #include <sysdep.h>
25 #include <string.h>
26 #include <sys/syscall.h>
27 #include <bp-checks.h>
29 #include <kernel-features.h>
30 #include <shlib-compat.h>
32 struct __old_msqid_ds
34 struct __old_ipc_perm msg_perm; /* structure describing operation permission */
35 struct msg *__unbounded __msg_first; /* pointer to first message on queue */
36 struct msg *__unbounded __msg_last; /* pointer to last message on queue */
37 __time_t msg_stime; /* time of last msgsnd command */
38 __time_t msg_rtime; /* time of last msgrcv command */
39 __time_t msg_ctime; /* time of last change */
40 struct wait_queue *__unbounded __wwait; /* ??? */
41 struct wait_queue *__unbounded __rwait; /* ??? */
42 unsigned short int __msg_cbytes; /* current number of bytes on queue */
43 unsigned short int msg_qnum; /* number of messages currently on queue */
44 unsigned short int msg_qbytes; /* max number of bytes allowed on queue */
45 __ipc_pid_t msg_lspid; /* pid of last msgsnd() */
46 __ipc_pid_t msg_lrpid; /* pid of last msgrcv() */
49 /* Allows to control internal state and destruction of message queue
50 objects. */
51 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
52 int __old_msgctl (int, int, struct __old_msqid_ds *);
53 #endif
54 int __new_msgctl (int, int, struct msqid_ds *);
56 #ifdef __NR_getuid32
57 # if __ASSUME_32BITUIDS == 0
58 /* This variable is shared with all files that need to check for 32bit
59 uids. */
60 extern int __libc_missing_32bit_uids;
61 # endif
62 #endif
64 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
65 int
66 attribute_compat_text_section
67 __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
69 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
70 msqid, cmd, 0, CHECK_1 (buf));
72 compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
73 #endif
75 int
76 __new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
78 #if __ASSUME_32BITUIDS > 0
79 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
80 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
81 #else
82 switch (cmd) {
83 case MSG_STAT:
84 case IPC_STAT:
85 case IPC_SET:
86 break;
87 default:
88 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
89 msqid, cmd, 0, CHECK_1 (buf));
93 int result;
94 struct __old_msqid_ds old;
96 #ifdef __NR_getuid32
97 if (__libc_missing_32bit_uids <= 0)
99 if (__libc_missing_32bit_uids < 0)
101 int save_errno = errno;
103 /* Test presence of new IPC by testing for getuid32 syscall. */
104 result = INLINE_SYSCALL (getuid32, 0);
105 if (result == -1 && errno == ENOSYS)
106 __libc_missing_32bit_uids = 1;
107 else
108 __libc_missing_32bit_uids = 0;
109 __set_errno(save_errno);
111 if (__libc_missing_32bit_uids <= 0)
113 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
114 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
115 return result;
118 #endif
119 if (cmd == IPC_SET)
121 old.msg_perm.uid = buf->msg_perm.uid;
122 old.msg_perm.gid = buf->msg_perm.gid;
123 old.msg_perm.mode = buf->msg_perm.mode;
124 old.msg_qbytes = buf->msg_qbytes;
125 if (old.msg_perm.uid != buf->msg_perm.uid ||
126 old.msg_perm.gid != buf->msg_perm.gid ||
127 old.msg_qbytes != buf->msg_qbytes)
129 __set_errno (EINVAL);
130 return -1;
133 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
134 msqid, cmd, 0, __ptrvalue (&old));
135 if (result != -1 && cmd != IPC_SET)
137 memset(buf, 0, sizeof(*buf));
138 buf->msg_perm.__key = old.msg_perm.__key;
139 buf->msg_perm.uid = old.msg_perm.uid;
140 buf->msg_perm.gid = old.msg_perm.gid;
141 buf->msg_perm.cuid = old.msg_perm.cuid;
142 buf->msg_perm.cgid = old.msg_perm.cgid;
143 buf->msg_perm.mode = old.msg_perm.mode;
144 buf->msg_perm.__seq = old.msg_perm.__seq;
145 buf->msg_stime = old.msg_stime;
146 buf->msg_rtime = old.msg_rtime;
147 buf->msg_ctime = old.msg_ctime;
148 buf->__msg_cbytes = old.__msg_cbytes;
149 buf->msg_qnum = old.msg_qnum;
150 buf->msg_qbytes = old.msg_qbytes;
151 buf->msg_lspid = old.msg_lspid;
152 buf->msg_lrpid = old.msg_lrpid;
154 return result;
156 #endif
159 versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);