posix_fadvise.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * posix_fadvise() for uClibc
  3. * http://www.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
  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. #ifdef __NR_arm_fadvise64_64
  11. /* We handle the 64bit alignment issue which is why the arm guys renamed their
  12. * syscall in the first place. So rename it back.
  13. */
  14. # define __NR_fadvise64_64 __NR_arm_fadvise64_64
  15. #endif
  16. #if defined(__NR_fadvise64) || defined(__NR_fadvise64_64)
  17. # include <fcntl.h>
  18. # include <endian.h>
  19. # include <bits/wordsize.h>
  20. # if defined(__NR_fadvise64_64)
  21. #include <_lfs_64.h>
  22. int posix_fadvise64(int fd, off64_t offset, off64_t len, int advice);
  23. int posix_fadvise(int fd, off_t offset, off_t len, int advice)
  24. {
  25. return posix_fadvise64(fd, offset, len, advice);
  26. }
  27. #else
  28. int posix_fadvise(int fd, off_t offset, off_t len, int advice)
  29. {
  30. int ret;
  31. INTERNAL_SYSCALL_DECL(err);
  32. # ifdef __NR_fadvise64_64
  33. # if __WORDSIZE == 64
  34. ret = INTERNAL_SYSCALL(fadvise64_64, err, 4, fd, offset, len, advice);
  35. # else
  36. # if defined (__arm__) || defined (__nds32__) || \
  37. (defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) && (defined(__powerpc__) || defined(__xtensa__)))
  38. /* arch with 64-bit data in even reg alignment #1: [powerpc/xtensa]
  39. * custom syscall handler (rearranges @advice to avoid register hole punch) */
  40. ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd, advice,
  41. OFF_HI_LO (offset), OFF_HI_LO (len));
  42. # elif defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
  43. /* arch with 64-bit data in even reg alignment #2: [arcv2/others-in-future]
  44. * stock syscall handler in kernel (reg hole punched) */
  45. ret = INTERNAL_SYSCALL(fadvise64_64, err, 7, fd, 0,
  46. OFF_HI_LO (offset), OFF_HI_LO (len), advice);
  47. # else
  48. ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd,
  49. OFF_HI_LO (offset), OFF_HI_LO (len), advice);
  50. # endif
  51. # endif
  52. # else /* __NR_fadvise64 */
  53. # if __WORDSIZE == 64
  54. ret = INTERNAL_SYSCALL(fadvise64, err, 4, fd, offset, len, advice);
  55. # else
  56. # if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
  57. ret = INTERNAL_SYSCALL(fadvise64, err, 6, fd, /*unused*/0,
  58. # else
  59. ret = INTERNAL_SYSCALL(fadvise64, err, 5, fd,
  60. # endif
  61. OFF_HI_LO (offset), len, advice);
  62. # endif
  63. # endif
  64. if (INTERNAL_SYSCALL_ERROR_P (ret, err))
  65. return INTERNAL_SYSCALL_ERRNO (ret, err);
  66. return 0;
  67. }
  68. # if !defined __NR_fadvise64_64 || __WORDSIZE == 64
  69. strong_alias(posix_fadvise,posix_fadvise64)
  70. # endif
  71. #endif
  72. #endif