remove obstack support
[uclibc-ng.git] / libc / misc / sysvipc / msgq.c
blob185cd268be69837b058eedbb73f2d508a4902478
1 #include <errno.h>
2 #include <sys/msg.h>
3 #include "ipc.h"
4 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
5 #include "sysdep-cancel.h"
6 #else
7 #define SINGLE_THREAD_P 1
8 #endif
11 #ifdef L_msgctl
13 #ifdef __NR_msgctl
14 #define __NR___libc_msgctl __NR_msgctl
15 static __inline__ _syscall3(int, __libc_msgctl, int, msqid, int, cmd, struct msqid_ds *, buf)
16 #endif
17 /* Message queue control operation. */
18 int msgctl(int msqid, int cmd, struct msqid_ds *buf)
20 #ifdef __NR_msgctl
21 return __libc_msgctl(msqid, cmd | __IPC_64, buf);
22 #else
23 return __syscall_ipc(IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf, 0);
24 #endif
26 #endif
29 #ifdef L_msgget
30 #ifdef __NR_msgget
31 _syscall2(int, msgget, key_t, key, int, msgflg)
32 #else
33 /* Get messages queue. */
34 int msgget (key_t key, int msgflg)
36 return __syscall_ipc(IPCOP_msgget ,key ,msgflg ,0 ,0, 0);
38 #endif
39 #endif
42 struct new_msg_buf{
43 struct msgbuf * oldmsg;
44 long int r_msgtyp; /* the fifth arg of __syscall_ipc */
46 /* Receive message from message queue. */
49 #ifdef L_msgrcv
50 #ifdef __NR_msgrcv
51 #define __NR___syscall_msgrcv __NR_msgrcv
52 static inline _syscall5(ssize_t, __syscall_msgrcv, int, msqid, void *, msgp,
53 size_t, msgsz, long int, msgtyp, int, msgflg)
54 #endif
55 static inline ssize_t do_msgrcv (int msqid, void *msgp, size_t msgsz,
56 long int msgtyp, int msgflg)
58 #ifdef __NR_msgrcv
59 return __syscall_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
60 #else
61 struct new_msg_buf temp;
63 temp.r_msgtyp = msgtyp;
64 temp.oldmsg = msgp;
65 return __syscall_ipc(IPCOP_msgrcv ,msqid ,msgsz ,msgflg ,&temp, 0);
66 #endif
68 ssize_t msgrcv (int msqid, void *msgp, size_t msgsz,
69 long int msgtyp, int msgflg)
71 if (SINGLE_THREAD_P)
72 return do_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
73 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
74 int oldtype = LIBC_CANCEL_ASYNC ();
75 int result = do_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
76 LIBC_CANCEL_RESET (oldtype);
77 return result;
78 #endif
80 #endif
84 #ifdef L_msgsnd
85 #ifdef __NR_msgsnd
86 #define __NR___syscall_msgsnd __NR_msgsnd
87 static inline _syscall4(int, __syscall_msgsnd, int, msqid, const void *, msgp,
88 size_t, msgsz, int, msgflg)
89 #endif
90 /* Send message to message queue. */
91 static inline int do_msgsnd (int msqid, const void *msgp, size_t msgsz,
92 int msgflg)
94 #ifdef __NR_msgsnd
95 return __syscall_msgsnd(msqid, msgp, msgsz, msgflg);
96 #else
97 return __syscall_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg, (void *)msgp, 0);
98 #endif
100 int msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
102 if (SINGLE_THREAD_P)
103 return do_msgsnd(msqid, msgp, msgsz, msgflg);
104 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
105 int oldtype = LIBC_CANCEL_ASYNC ();
106 int result = do_msgsnd(msqid, msgp, msgsz, msgflg);
107 LIBC_CANCEL_RESET (oldtype);
108 return result;
109 #endif
111 #endif