__syscall_fcntl.c 1.5 KB

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