msgq.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <errno.h>
  2. #include <sys/msg.h>
  3. #include "ipc.h"
  4. #ifdef L_msgctl
  5. #ifdef __NR_msgctl
  6. #define __NR___libc_msgctl __NR_msgctl
  7. static inline _syscall3(int, __libc_msgctl, int, msqid, int, cmd, struct msqid_ds *, buf);
  8. #endif
  9. /* Message queue control operation. */
  10. int msgctl(int msqid, int cmd, struct msqid_ds *buf)
  11. {
  12. #ifdef __NR_msgctl
  13. return __libc_msgctl(msqid, cmd | __IPC_64, buf);
  14. #else
  15. return __syscall_ipc(IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf);
  16. #endif
  17. }
  18. #endif
  19. #ifdef L_msgget
  20. #ifdef __NR_msgget
  21. _syscall2(int, msgget, key_t, key, int, msgflg)
  22. #else
  23. /* Get messages queue. */
  24. int msgget (key_t key, int msgflg)
  25. {
  26. return __syscall_ipc(IPCOP_msgget ,key ,msgflg ,0 ,0);
  27. }
  28. #endif
  29. #endif
  30. struct new_msg_buf{
  31. struct msgbuf * oldmsg;
  32. long int r_msgtyp; /* the fifth arg of __syscall_ipc */
  33. };
  34. /* Receive message from message queue. */
  35. #ifdef L_msgrcv
  36. #ifdef __NR_msgrcv
  37. _syscall5(int, msgrcv, int, msqid, void *, msgp, size_t, msgsz, long int, msgtyp, int, msgflg);
  38. #else
  39. int msgrcv (int msqid, void *msgp, size_t msgsz,
  40. long int msgtyp, int msgflg)
  41. {
  42. struct new_msg_buf temp;
  43. temp.r_msgtyp = msgtyp;
  44. temp.oldmsg = msgp;
  45. return __syscall_ipc(IPCOP_msgrcv ,msqid ,msgsz ,msgflg ,&temp);
  46. }
  47. #endif
  48. #endif
  49. #ifdef L_msgsnd
  50. #ifdef __NR_msgsnd
  51. _syscall4(int, msgsnd, int, msqid, const void *, msgp, size_t, msgsz, int, msgflg);
  52. #else
  53. /* Send message to message queue. */
  54. int msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
  55. {
  56. return __syscall_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg, (void *)msgp);
  57. }
  58. #endif
  59. #endif