__syscall_fcntl.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifdef __NEW_THREADS
  39. int oldtype, result;
  40. #endif
  41. va_start (ap, cmd);
  42. arg = va_arg (ap, long);
  43. va_end (ap);
  44. if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
  45. #if defined __NR_fcntl
  46. return __NC(fcntl)(fd, cmd, arg);
  47. #else
  48. return INLINE_SYSCALL(fcntl64, 3, fd, cmd, arg);
  49. #endif
  50. #ifdef __NEW_THREADS
  51. oldtype = LIBC_CANCEL_ASYNC ();
  52. #if defined __NR_fcntl
  53. result = __NC(fcntl)(fd, cmd, arg);
  54. #else
  55. result = INLINE_SYSCALL(fcntl64, 3, fd, cmd, arg);
  56. #endif
  57. LIBC_CANCEL_RESET (oldtype);
  58. return result;
  59. #endif
  60. }
  61. lt_strong_alias(fcntl)
  62. lt_libc_hidden(fcntl)
  63. #if defined __UCLIBC_HAS_LFS__ && !defined __NR_fcntl64 && __WORDSIZE == 32
  64. strong_alias_untyped(fcntl,fcntl64)
  65. lt_strong_alias(fcntl64)
  66. lt_libc_hidden(fcntl64)
  67. #endif