__syscall_fcntl.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  20. int __fcntl_nocancel (int fd, int cmd, ...)
  21. {
  22. va_list ap;
  23. void *arg;
  24. va_start (ap, cmd);
  25. arg = va_arg (ap, void *);
  26. va_end (ap);
  27. # if __WORDSIZE == 32
  28. if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
  29. # if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  30. return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
  31. # else
  32. __set_errno(ENOSYS);
  33. return -1;
  34. # endif
  35. }
  36. # endif
  37. return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
  38. }
  39. #endif
  40. int __libc_fcntl (int fd, int cmd, ...)
  41. {
  42. va_list ap;
  43. void *arg;
  44. va_start (ap, cmd);
  45. arg = va_arg (ap, void *);
  46. va_end (ap);
  47. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  48. if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
  49. # if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  50. return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
  51. # else
  52. return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
  53. # endif
  54. int oldtype = LIBC_CANCEL_ASYNC ();
  55. # if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  56. int result = INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
  57. # else
  58. int result = INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
  59. # endif
  60. LIBC_CANCEL_RESET (oldtype);
  61. return result;
  62. #else
  63. # if __WORDSIZE == 32
  64. if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
  65. # if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
  66. return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
  67. # else
  68. __set_errno(ENOSYS);
  69. return -1;
  70. # endif
  71. }
  72. # endif
  73. return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
  74. #endif
  75. }
  76. libc_hidden_def(__libc_fcntl)
  77. libc_hidden_proto(fcntl)
  78. weak_alias(__libc_fcntl,fcntl)
  79. libc_hidden_weak(fcntl)