posix_fadvise.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * posix_fadvise() for uClibc
  4. * http://www.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
  5. *
  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. #ifdef __NR_arm_fadvise64_64
  12. /* We handle the 64bit alignment issue which is why the arm guys renamed their
  13. * syscall in the first place. So rename it back.
  14. */
  15. # define __NR_fadvise64_64 __NR_arm_fadvise64_64
  16. #endif
  17. #if defined(__NR_fadvise64) || defined(__NR_fadvise64_64)
  18. # include <fcntl.h>
  19. # include <endian.h>
  20. # include <bits/wordsize.h>
  21. # if defined(__NR_fadvise64_64) && defined(__UCLIBC_HAS_LFS__)
  22. #include <_lfs_64.h>
  23. int posix_fadvise64(int fd, off64_t offset, off64_t len, int advice);
  24. int posix_fadvise(int fd, off_t offset, off_t len, int advice)
  25. {
  26. return posix_fadvise64(fd, offset, len, advice);
  27. }
  28. #else
  29. int posix_fadvise(int fd, off_t offset, off_t len, int advice)
  30. {
  31. int ret;
  32. INTERNAL_SYSCALL_DECL(err);
  33. # ifdef __NR_fadvise64_64
  34. # if __WORDSIZE == 64
  35. ret = INTERNAL_SYSCALL(fadvise64_64, err, 4, fd, offset, len, advice);
  36. # else
  37. # if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) || defined(__arm__)
  38. ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd, advice,
  39. OFF_HI_LO (offset), OFF_HI_LO (len));
  40. # else
  41. ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd,
  42. OFF_HI_LO (offset), OFF_HI_LO (len), advice);
  43. # endif
  44. # endif
  45. # else /* __NR_fadvise64 */
  46. # if __WORDSIZE == 64
  47. ret = INTERNAL_SYSCALL(fadvise64, err, 4, fd, offset, len, advice);
  48. # else
  49. # if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
  50. ret = INTERNAL_SYSCALL(fadvise64, err, 6, fd, /*unused*/0,
  51. # else
  52. ret = INTERNAL_SYSCALL(fadvise64, err, 5, fd,
  53. # endif
  54. OFF_HI_LO (offset), len, advice);
  55. # endif
  56. # endif
  57. if (INTERNAL_SYSCALL_ERROR_P (ret, err))
  58. return INTERNAL_SYSCALL_ERRNO (ret, err);
  59. return 0;
  60. }
  61. # if defined __UCLIBC_HAS_LFS__ && (!defined __NR_fadvise64_64 || __WORDSIZE == 64)
  62. strong_alias(posix_fadvise,posix_fadvise64)
  63. # endif
  64. #endif
  65. #endif