mqueue.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Copyright (C) 2004-2026 Free Software Foundation, Inc.
  17. This file is part of the GNU C Library.
  18. The GNU C Library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Lesser General Public
  20. License as published by the Free Software Foundation; either
  21. version 2.1 of the License, or (at your option) any later version.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library; if not, see
  28. <https://www.gnu.org/licenses/>. */
  29. #ifndef _MQUEUE_H
  30. #define _MQUEUE_H 1
  31. #include <features.h>
  32. #include <sys/types.h>
  33. #include <fcntl.h>
  34. #include <bits/types/sigevent_t.h>
  35. #include <bits/types/struct_timespec.h>
  36. /* Get the definition of mqd_t and struct mq_attr. */
  37. #include <bits/mqueue.h>
  38. __BEGIN_DECLS
  39. /* Establish connection between a process and a message queue NAME and
  40. return message queue descriptor or (mqd_t) -1 on error. OFLAG determines
  41. the type of access used. If O_CREAT is on OFLAG, the third argument is
  42. taken as a `mode_t', the mode of the created message queue, and the fourth
  43. argument is taken as `struct mq_attr *', pointer to message queue
  44. attributes. If the fourth argument is NULL, default attributes are
  45. used. */
  46. extern mqd_t mq_open (const char *__name, int __oflag, ...)
  47. __THROW __nonnull ((1));
  48. /* Removes the association between message queue descriptor MQDES and its
  49. message queue. */
  50. extern int mq_close (mqd_t __mqdes) __THROW;
  51. /* Query status and attributes of message queue MQDES. */
  52. extern int mq_getattr (mqd_t __mqdes, struct mq_attr *__mqstat)
  53. __THROW __nonnull ((2));
  54. /* Set attributes associated with message queue MQDES and if OMQSTAT is
  55. not NULL also query its old attributes. */
  56. extern int mq_setattr (mqd_t __mqdes,
  57. const struct mq_attr *__restrict __mqstat,
  58. struct mq_attr *__restrict __omqstat)
  59. __THROW __nonnull ((2));
  60. /* Remove message queue named NAME. */
  61. extern int mq_unlink (const char *__name) __THROW __nonnull ((1));
  62. /* Register notification issued upon message arrival to an empty
  63. message queue MQDES. */
  64. extern int mq_notify (mqd_t __mqdes, const struct sigevent *__notification)
  65. __THROW;
  66. /* Receive the oldest from highest priority messages in message queue
  67. MQDES. */
  68. extern ssize_t mq_receive (mqd_t __mqdes, char *__msg_ptr, size_t __msg_len,
  69. unsigned int *__msg_prio) __nonnull ((2));
  70. /* Add message pointed by MSG_PTR to message queue MQDES. */
  71. extern int mq_send (mqd_t __mqdes, const char *__msg_ptr, size_t __msg_len,
  72. unsigned int __msg_prio) __nonnull ((2));
  73. #ifdef __USE_XOPEN2K
  74. # ifndef __USE_TIME64_REDIRECTS
  75. /* Receive the oldest from highest priority messages in message queue
  76. MQDES, stop waiting if ABS_TIMEOUT expires. */
  77. extern ssize_t mq_timedreceive (mqd_t __mqdes, char *__restrict __msg_ptr,
  78. size_t __msg_len,
  79. unsigned int *__restrict __msg_prio,
  80. const struct timespec *__restrict __abs_timeout)
  81. __nonnull ((2, 5));
  82. /* Add message pointed by MSG_PTR to message queue MQDES, stop blocking
  83. on full message queue if ABS_TIMEOUT expires. */
  84. extern int mq_timedsend (mqd_t __mqdes, const char *__msg_ptr,
  85. size_t __msg_len, unsigned int __msg_prio,
  86. const struct timespec *__abs_timeout)
  87. __nonnull ((2, 5));
  88. # else
  89. # ifdef __REDIRECT
  90. extern int __REDIRECT (mq_timedreceive, (mqd_t __mqdes,
  91. char *__restrict __msg_ptr,
  92. size_t __msg_len,
  93. unsigned int *__restrict __msg_prio,
  94. const struct timespec *__restrict __abs_timeout),
  95. __mq_timedreceive_time64)
  96. __nonnull ((2, 5));
  97. extern int __REDIRECT (mq_timedsend, (mqd_t __mqdes,
  98. const char *__msg_ptr, size_t __msg_len,
  99. unsigned int __msg_prio,
  100. const struct timespec *__abs_timeout),
  101. __mq_timedsend_time64)
  102. __nonnull ((2, 5));
  103. # else
  104. # define mq_timedreceive __mq_timedreceive_time64
  105. # define mq_timedsend __mq_timedsend_time64
  106. # endif
  107. # endif
  108. #endif
  109. /* Define some inlines helping to catch common problems. */
  110. #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
  111. # include <bits/mqueue2.h>
  112. #endif
  113. __END_DECLS
  114. #endif /* mqueue.h */