mq_open.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * mq_open.c - open a message queue.
  3. */
  4. #include <errno.h>
  5. #include <stdarg.h>
  6. #include <stddef.h>
  7. #include <sys/syscall.h>
  8. #include <mqueue.h>
  9. #ifdef __NR_mq_open
  10. #define __NR___syscall_mq_open __NR_mq_open
  11. static __inline__ _syscall4(int, __syscall_mq_open, const char *, name,
  12. int, oflag, __kernel_mode_t, mode, void *, attr);
  13. /*
  14. * Establish connection between a process and a message queue and
  15. * return message queue descriptor or (mqd_t) -1 on error.
  16. * oflag determines the type of access used. If O_CREAT is on oflag, the
  17. * third argument is taken as a `mode_t', the mode of the created
  18. * message queue, and the fourth argument is taken as `struct mq_attr *',
  19. * pointer to message queue attributes.
  20. * If the fourth argument is NULL, default attributes are used.
  21. */
  22. mqd_t mq_open(const char *name, int oflag, ...)
  23. {
  24. mode_t mode;
  25. struct mq_attr *attr;
  26. if (name[0] != '/') {
  27. __set_errno(EINVAL);
  28. return -1;
  29. }
  30. mode = 0;
  31. attr = NULL;
  32. if (oflag & O_CREAT) {
  33. va_list ap;
  34. va_start(ap, oflag);
  35. mode = va_arg(ap, mode_t);
  36. attr = va_arg(ap, struct mq_attr *);
  37. va_end(ap);
  38. }
  39. return __syscall_mq_open(name + 1, oflag, mode, attr);
  40. }
  41. #endif