mq_open.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 2004-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <errno.h>
  15. #include <mqueue.h>
  16. #include <stdarg.h>
  17. #include <stddef.h>
  18. #include <stdio.h>
  19. #include <sysdep.h>
  20. #ifdef __NR_mq_open
  21. /* Establish connection between a process and a message queue NAME and
  22. return message queue descriptor or (mqd_t) -1 on error. OFLAG determines
  23. the type of access used. If O_CREAT is on OFLAG, the third argument is
  24. taken as a `mode_t', the mode of the created message queue, and the fourth
  25. argument is taken as `struct mq_attr *', pointer to message queue
  26. attributes. If the fourth argument is NULL, default attributes are
  27. used. */
  28. mqd_t
  29. __mq_open (const char *name, int oflag, ...)
  30. {
  31. if (name[0] != '/')
  32. return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
  33. mode_t mode = 0;
  34. struct mq_attr *attr = NULL;
  35. if (oflag & O_CREAT)
  36. {
  37. va_list ap;
  38. va_start (ap, oflag);
  39. mode = va_arg (ap, mode_t);
  40. attr = va_arg (ap, struct mq_attr *);
  41. va_end (ap);
  42. }
  43. return INLINE_SYSCALL (mq_open, 4, name + 1, oflag, mode, attr);
  44. }
  45. strong_alias (__mq_open, mq_open);
  46. mqd_t
  47. __mq_open_2 (const char *name, int oflag)
  48. {
  49. if (oflag & O_CREAT)
  50. __fortify_fail ("invalid mq_open call: O_CREAT without mode and attr");
  51. return __mq_open (name, oflag);
  52. }
  53. #else
  54. # include <rt/mq_open.c>
  55. #endif