mq_unlink.c 652 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * mq_unlink.c - remove a message queue.
  3. */
  4. #include <errno.h>
  5. #include <sys/syscall.h>
  6. #include <mqueue.h>
  7. #ifdef __NR_mq_unlink
  8. #define __NR___syscall_mq_unlink __NR_mq_unlink
  9. static inline _syscall1(int, __syscall_mq_unlink, const char *, name);
  10. /* Remove message queue */
  11. int mq_unlink(const char *name)
  12. {
  13. int ret;
  14. if (name[0] != '/') {
  15. __set_errno(EINVAL);
  16. return -1;
  17. }
  18. ret = __syscall_mq_unlink(name + 1);
  19. /* While unlink can return either EPERM or EACCES, mq_unlink should return just EACCES. */
  20. if (ret < 0) {
  21. ret = errno;
  22. if (ret == EPERM)
  23. ret = EACCES;
  24. __set_errno(ret);
  25. ret = -1;
  26. }
  27. return ret;
  28. }
  29. #endif