__syscall_fcntl.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include <cancel.h> /* Must come before <fcntl.h>. */
  13. #include <fcntl.h>
  14. #include <bits/wordsize.h>
  15. int __NC(fcntl)(int fd, int cmd, long arg)
  16. {
  17. #if __WORDSIZE == 32
  18. if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
  19. # if (defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64) || !defined __NR_fcntl
  20. return INLINE_SYSCALL(fcntl64, 3, fd, cmd, arg);
  21. # else
  22. __set_errno(ENOSYS);
  23. return -1;
  24. # endif
  25. }
  26. #endif
  27. #if defined __NR_fcntl
  28. return INLINE_SYSCALL(fcntl, 3, fd, cmd, arg);
  29. #else
  30. __set_errno(ENOSYS);
  31. return -1;
  32. #endif
  33. }
  34. int fcntl(int fd, int cmd, ...)
  35. {
  36. va_list ap;
  37. long arg;
  38. va_start (ap, cmd);
  39. arg = va_arg (ap, long);
  40. va_end (ap);
  41. if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
  42. #if defined __NR_fcntl
  43. return __NC(fcntl)(fd, cmd, arg);
  44. #else
  45. return INLINE_SYSCALL(fcntl64, 3, fd, cmd, arg);
  46. #endif
  47. #ifdef __NEW_THREADS
  48. int oldtype = LIBC_CANCEL_ASYNC ();
  49. #if defined __NR_fcntl
  50. int result = __NC(fcntl)(fd, cmd, arg);
  51. #else
  52. int result = INLINE_SYSCALL(fcntl64, 3, fd, cmd, arg);
  53. #endif
  54. LIBC_CANCEL_RESET (oldtype);
  55. return result;
  56. #endif
  57. }
  58. lt_strong_alias(fcntl)
  59. lt_libc_hidden(fcntl)
  60. #if defined __UCLIBC_HAS_LFS__ && !defined __NR_fcntl64 && __WORDSIZE == 32
  61. strong_alias_untyped(fcntl,fcntl64)
  62. lt_strong_alias(fcntl64)
  63. lt_libc_hidden(fcntl64)
  64. #endif