fcntl_nocancel.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Linux fcntl syscall implementation -- non-cancellable.
  2. Copyright (C) 2018-2019 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. <http://www.gnu.org/licenses/>. */
  15. #include <fcntl.h>
  16. #include <stdarg.h>
  17. #include <errno.h>
  18. #include <sysdep-cancel.h>
  19. #include <not-cancel.h>
  20. #ifndef __NR_fcntl64
  21. # define __NR_fcntl64 __NR_fcntl
  22. #endif
  23. #ifndef FCNTL_ADJUST_CMD
  24. # define FCNTL_ADJUST_CMD(__cmd) __cmd
  25. #endif
  26. int
  27. __fcntl64_nocancel (int fd, int cmd, ...)
  28. {
  29. va_list ap;
  30. void *arg;
  31. va_start (ap, cmd);
  32. arg = va_arg (ap, void *);
  33. va_end (ap);
  34. cmd = FCNTL_ADJUST_CMD (cmd);
  35. return __fcntl64_nocancel_adjusted (fd, cmd, arg);
  36. }
  37. hidden_def (__fcntl64_nocancel)
  38. int
  39. __fcntl64_nocancel_adjusted (int fd, int cmd, void *arg)
  40. {
  41. if (cmd == F_GETOWN)
  42. {
  43. INTERNAL_SYSCALL_DECL (err);
  44. struct f_owner_ex fex;
  45. int res = INTERNAL_SYSCALL_CALL (fcntl64, err, fd, F_GETOWN_EX, &fex);
  46. if (!INTERNAL_SYSCALL_ERROR_P (res, err))
  47. return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
  48. return INLINE_SYSCALL_ERROR_RETURN_VALUE
  49. (INTERNAL_SYSCALL_ERRNO (res, err));
  50. }
  51. return INLINE_SYSCALL_CALL (fcntl64, fd, cmd, (void *) arg);
  52. }