lseek.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * lseek() for uClibc
  4. *
  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 <unistd.h>
  11. #include <cancel.h>
  12. #ifdef __NR_lseek
  13. # define __NR___lseek_nocancel __NR_lseek
  14. _syscall3(off_t, __NC(lseek), int, fd, off_t, offset, int, whence)
  15. /* Use lseek64 if __NR_lseek is not defined but UCLIBC_HAS_LFS is enabled */
  16. #elif !defined __NR_lseek && defined __NR_llseek
  17. #include <endian.h>
  18. off_t __NC(lseek)(int fd, off_t offset, int whence)
  19. {
  20. #if defined __UCLIBC_HAS_LFS__
  21. return lseek64(fd, offset, whence);
  22. #elif __WORDSIZE == 32
  23. __off64_t result;
  24. __off_t high = 0;
  25. return INLINE_SYSCALL(llseek, 5, fd,
  26. __LONG_LONG_PAIR(high, offset),
  27. &result, whence) ?: result;
  28. #endif
  29. /* No need to handle __WORDSIZE == 64 as such a kernel won't define __NR_llseek */
  30. }
  31. #else
  32. # include <errno.h>
  33. off_t __NC(lseek)(int fd, off_t offset attribute_unused, int whence)
  34. {
  35. if (fd < 0) {
  36. __set_errno(EBADF);
  37. return -1;
  38. }
  39. switch(whence) {
  40. case SEEK_SET:
  41. case SEEK_CUR:
  42. case SEEK_END:
  43. break;
  44. default:
  45. __set_errno(EINVAL);
  46. return -1;
  47. }
  48. __set_errno(ENOSYS);
  49. return -1;
  50. }
  51. #endif
  52. CANCELLABLE_SYSCALL(off_t, lseek, (int fd, off_t offset, int whence), (fd, offset, whence))
  53. lt_libc_hidden(lseek)
  54. #if defined __UCLIBC_HAS_LFS__ && (__WORDSIZE == 64 || (!defined __NR__llseek && !defined __NR_llseek))
  55. strong_alias_untyped(__NC(lseek),__NC(lseek64))
  56. strong_alias_untyped(lseek,lseek64)
  57. lt_strong_alias(lseek64)
  58. lt_libc_hidden(lseek64)
  59. #endif