posix_fadvise.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. # ifdef __NR_fadvise64_64
  22. int posix_fadvise64(int fd, off64_t offset, off64_t len, int advice);
  23. # endif
  24. int posix_fadvise(int fd, off_t offset, off_t len, int advice)
  25. {
  26. # ifdef __NR_fadvise64_64
  27. return posix_fadvise64(fd, offset, len, advice);
  28. # else
  29. int ret;
  30. INTERNAL_SYSCALL_DECL(err);
  31. # if __WORDSIZE == 64
  32. ret = INTERNAL_SYSCALL(fadvise64, err, 4, fd, offset, len, advice);
  33. # else
  34. # if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
  35. ret = INTERNAL_SYSCALL(fadvise64, err, 6, fd, /*unused*/0,
  36. # else
  37. ret = INTERNAL_SYSCALL(fadvise64, err, 5, fd,
  38. # endif
  39. OFF_HI_LO (offset), len, advice);
  40. # endif
  41. if (INTERNAL_SYSCALL_ERROR_P (ret, err))
  42. return INTERNAL_SYSCALL_ERRNO (ret, err);
  43. return 0;
  44. # endif
  45. }
  46. # if defined __UCLIBC_HAS_LFS__ && (!defined __NR_fadvise64_64 || __WORDSIZE == 64)
  47. strong_alias(posix_fadvise,posix_fadvise64)
  48. # endif
  49. #endif