mqueue2.h 3.0 KB

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