]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/ipc/msgctl.c
WASI libc prototype implementation.
[wasi-libc.git] / libc-top-half / musl / src / ipc / msgctl.c
1 #include <sys/msg.h>
2 #include <endian.h>
3 #include "syscall.h"
4 #include "ipc.h"
5
6 #if __BYTE_ORDER != __BIG_ENDIAN
7 #undef SYSCALL_IPC_BROKEN_MODE
8 #endif
9
10 int msgctl(int q, int cmd, struct msqid_ds *buf)
11 {
12 #ifdef SYSCALL_IPC_BROKEN_MODE
13 struct msqid_ds tmp;
14 if (cmd == IPC_SET) {
15 tmp = *buf;
16 tmp.msg_perm.mode *= 0x10000U;
17 buf = &tmp;
18 }
19 #endif
20 #ifdef SYS_msgctl
21 int r = __syscall(SYS_msgctl, q, cmd | IPC_64, buf);
22 #else
23 int r = __syscall(SYS_ipc, IPCOP_msgctl, q, cmd | IPC_64, 0, buf, 0);
24 #endif
25 #ifdef SYSCALL_IPC_BROKEN_MODE
26 if (r >= 0) switch (cmd) {
27 case IPC_STAT:
28 case MSG_STAT:
29 case MSG_STAT_ANY:
30 buf->msg_perm.mode >>= 16;
31 }
32 #endif
33 return __syscall_ret(r);
34 }