lseek.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * lseek() for uClibc
  3. *
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <sys/syscall.h>
  9. #include <unistd.h>
  10. #include <cancel.h>
  11. #ifdef __NR_lseek
  12. # define __NR___lseek_nocancel __NR_lseek
  13. _syscall3(off_t, __NC(lseek), int, fd, off_t, offset, int, whence)
  14. #elif !defined __NR_lseek && defined __NR_llseek
  15. #include <endian.h>
  16. off_t __NC(lseek)(int fd, off_t offset, int whence)
  17. {
  18. #if __WORDSIZE == 32
  19. __off64_t result;
  20. return INLINE_SYSCALL(llseek, 5, fd,
  21. (long) (((uint64_t) (offset)) >> 32),
  22. (long) offset, &result, whence) ?: result;
  23. #else
  24. return lseek64(fd, offset, whence);
  25. #endif
  26. /* No need to handle __WORDSIZE == 64 as such a kernel won't define __NR_llseek */
  27. }
  28. #else
  29. # include <errno.h>
  30. off_t __NC(lseek)(int fd, off_t offset attribute_unused, int whence)
  31. {
  32. if (fd < 0) {
  33. __set_errno(EBADF);
  34. return -1;
  35. }
  36. switch(whence) {
  37. case SEEK_SET:
  38. case SEEK_CUR:
  39. case SEEK_END:
  40. case SEEK_DATA:
  41. case SEEK_HOLE:
  42. break;
  43. default:
  44. __set_errno(EINVAL);
  45. return -1;
  46. }
  47. __set_errno(ENOSYS);
  48. return -1;
  49. }
  50. #endif
  51. CANCELLABLE_SYSCALL(off_t, lseek, (int fd, off_t offset, int whence), (fd, offset, whence))
  52. lt_libc_hidden(lseek)
  53. #if __WORDSIZE == 64 || (!defined __NR__llseek && !defined __NR_llseek)
  54. strong_alias_untyped(__NC(lseek),__NC(lseek64))
  55. strong_alias_untyped(lseek,lseek64)
  56. lt_strong_alias(lseek64)
  57. lt_libc_hidden(lseek64)
  58. #endif