mqueue2.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /* Checking macros for mq functions.
  17. Copyright (C) 2007-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library.
  19. The GNU C Library is free software; you can redistribute it and/or
  20. modify it under the terms of the GNU Lesser General Public
  21. License as published by the Free Software Foundation; either
  22. version 2.1 of the License, or (at your option) any later version.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. #ifndef _FCNTL_H
  31. # error "Never include <bits/mqueue2.h> directly; use <mqueue.h> instead."
  32. #endif
  33. /* Check that calls to mq_open with O_CREAT set have an appropriate third and fourth
  34. parameter. */
  35. extern mqd_t mq_open (const char *__name, int __oflag, ...)
  36. __THROW __nonnull ((1));
  37. extern mqd_t __mq_open_2 (const char *__name, int __oflag)
  38. __THROW __nonnull ((1));
  39. extern mqd_t __REDIRECT_NTH (__mq_open_alias, (const char *__name,
  40. int __oflag, ...), mq_open)
  41. __nonnull ((1));
  42. #ifdef __va_arg_pack_len
  43. __errordecl (__mq_open_wrong_number_of_args,
  44. "mq_open can be called either with 2 or 4 arguments");
  45. __errordecl (__mq_open_missing_mode_and_attr,
  46. "mq_open with O_CREAT in second argument needs 4 arguments");
  47. __fortify_function mqd_t
  48. __NTH (mq_open (const char *__name, int __oflag, ...))
  49. {
  50. if (__va_arg_pack_len () != 0 && __va_arg_pack_len () != 2)
  51. __mq_open_wrong_number_of_args ();
  52. if (__builtin_constant_p (__oflag))
  53. {
  54. if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () == 0)
  55. {
  56. __mq_open_missing_mode_and_attr ();
  57. return __mq_open_2 (__name, __oflag);
  58. }
  59. return __mq_open_alias (__name, __oflag, __va_arg_pack ());
  60. }
  61. if (__va_arg_pack_len () == 0)
  62. return __mq_open_2 (__name, __oflag);
  63. return __mq_open_alias (__name, __oflag, __va_arg_pack ());
  64. }
  65. #elif __fortify_use_clang
  66. __fortify_function_error_function __attribute_overloadable__ mqd_t
  67. __NTH (mq_open (__fortify_clang_overload_arg (const char *, , __name),
  68. int __oflag, mode_t __mode, ...))
  69. __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments");
  70. __fortify_function __attribute_overloadable__ mqd_t
  71. __NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
  72. int __oflag, mode_t __mode, struct mq_attr *__attr))
  73. {
  74. return __mq_open_alias (__name, __oflag, __mode, __attr);
  75. }
  76. __fortify_function __attribute_overloadable__ mqd_t
  77. __NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
  78. int __oflag))
  79. __fortify_clang_prefer_this_overload
  80. __fortify_clang_error ((__oflag & O_CREAT),
  81. "mq_open with O_CREAT in second argument needs 4 arguments")
  82. {
  83. return __mq_open_alias (__name, __oflag);
  84. }
  85. #endif