__syscall_fcntl.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * __syscall_fcntl() for uClibc
  4. *
  5. * Copyright (C) 2006 Steven J. Hill <sjhill@realitydiluted.com>
  6. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  7. *
  8. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  9. */
  10. #include <sys/syscall.h>
  11. #include <stdarg.h>
  12. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  13. #include <sysdep-cancel.h> /* Must come before <fcntl.h>. */
  14. #endif
  15. #include <fcntl.h>
  16. #include <bits/wordsize.h>
  17. extern __typeof(fcntl) __libc_fcntl;
  18. libc_hidden_proto(__libc_fcntl)
  19. int __fcntl_nocancel (int fd, int cmd, ...)
  20. {
  21. va_list ap;
  22. void *arg;
  23. va_start (ap, cmd);
  24. arg = va_arg (ap, void *);
  25. va_end (ap);
  26. # if __WORDSIZE == 32
  27. if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
  28. # if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  29. return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
  30. # else
  31. __set_errno(ENOSYS);
  32. return -1;
  33. # endif
  34. }
  35. # endif
  36. return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
  37. }
  38. libc_hidden_def(__fcntl_nocancel)
  39. int __libc_fcntl (int fd, int cmd, ...)
  40. {
  41. va_list ap;
  42. void *arg;
  43. va_start (ap, cmd);
  44. arg = va_arg (ap, void *);
  45. va_end (ap);
  46. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  47. if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
  48. # if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  49. return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
  50. # else
  51. return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
  52. # endif
  53. int oldtype = LIBC_CANCEL_ASYNC ();
  54. # if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  55. int result = INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
  56. # else
  57. int result = INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
  58. # endif
  59. LIBC_CANCEL_RESET (oldtype);
  60. return result;
  61. #else
  62. # if __WORDSIZE == 32
  63. if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
  64. # if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  65. return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
  66. # else
  67. __set_errno(ENOSYS);
  68. return -1;
  69. # endif
  70. }
  71. # endif
  72. return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
  73. #endif
  74. }
  75. libc_hidden_def(__libc_fcntl)
  76. libc_hidden_proto(fcntl)
  77. weak_alias(__libc_fcntl,fcntl)
  78. libc_hidden_weak(fcntl)