posix_fadvise64.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * posix_fadvise64() 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 <features.h>
  11. #include <unistd.h>
  12. #include <errno.h>
  13. #include <endian.h>
  14. #include <stdint.h>
  15. #include <sys/types.h>
  16. #include <sys/syscall.h>
  17. #include <fcntl.h>
  18. #ifdef __UCLIBC_HAS_LFS__
  19. #ifdef __NR_fadvise64_64
  20. /* 64 bit implementation is cake ... or more like pie ... */
  21. #if __WORDSIZE == 64
  22. #define __NR_posix_fadvise64 __NR_fadvise64_64
  23. _syscall4(int, posix_fadvise64, int, fd, __off64_t, offset,
  24. __off64_t, len, int, advice);
  25. /* 32 bit implementation is kind of a pita */
  26. #elif __WORDSIZE == 32
  27. #ifdef _syscall6 /* workaround until everyone has _syscall6() */
  28. #define __NR___syscall_fadvise64_64 __NR_fadvise64_64
  29. static inline _syscall6(int, __syscall_fadvise64_64, int, fd,
  30. unsigned long, high_offset, unsigned long, low_offset,
  31. unsigned long, high_len, unsigned long, low_len,
  32. int, advice);
  33. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  34. {
  35. return (__syscall_fadvise64_64(fd,
  36. __LONG_LONG_PAIR(offset >> 32, offset & 0xffffffff),
  37. __LONG_LONG_PAIR(len >> 32, len & 0xffffffff),
  38. advice));
  39. }
  40. #else
  41. #warning _syscall6 has not been defined for your machine :(
  42. #endif /* _syscall6 */
  43. #else
  44. #error your machine is neither 32 bit or 64 bit ... it must be magical
  45. #endif
  46. #elif !defined __NR_fadvise64
  47. /* This is declared as a strong alias in posix_fadvise.c if __NR_fadvise64
  48. * is defined.
  49. */
  50. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  51. {
  52. __set_errno(ENOSYS);
  53. return -1;
  54. }
  55. #endif /* __NR_fadvise64_64 */
  56. #endif /* __UCLIBC_HAS_LFS__ */