posix_fadvise64.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifdef INTERNAL_SYSCALL
  24. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  25. {
  26. if (len != (off_t) len)
  27. return EOVERFLOW;
  28. INTERNAL_SYSCALL_DECL (err);
  29. int ret = INTERNAL_SYSCALL (posix_fadvise64, err, 5, fd,
  30. __LONG_LONG_PAIR ((long) (offset >> 32),
  31. (long) offset),
  32. (off_t) len, advice);
  33. if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
  34. return 0;
  35. return INTERNAL_SYSCALL_ERRNO (ret, err);
  36. }
  37. #else
  38. _syscall4(int, posix_fadvise64, int, fd, __off64_t, offset,
  39. __off64_t, len, int, advice);
  40. #endif
  41. /* 32 bit implementation is kind of a pita */
  42. #elif __WORDSIZE == 32
  43. #ifdef _syscall6 /* workaround until everyone has _syscall6() */
  44. #define __NR___syscall_fadvise64_64 __NR_fadvise64_64
  45. static inline _syscall6(int, __syscall_fadvise64_64, int, fd,
  46. unsigned long, high_offset, unsigned long, low_offset,
  47. unsigned long, high_len, unsigned long, low_len,
  48. int, advice);
  49. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  50. {
  51. return (__syscall_fadvise64_64(fd,
  52. __LONG_LONG_PAIR(offset >> 32, offset & 0xffffffff),
  53. __LONG_LONG_PAIR(len >> 32, len & 0xffffffff),
  54. advice));
  55. }
  56. #else
  57. #warning _syscall6 has not been defined for your machine :(
  58. #endif /* _syscall6 */
  59. #else
  60. #error your machine is neither 32 bit or 64 bit ... it must be magical
  61. #endif
  62. #elif !defined __NR_fadvise64
  63. /* This is declared as a strong alias in posix_fadvise.c if __NR_fadvise64
  64. * is defined.
  65. */
  66. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  67. {
  68. return ENOSYS;
  69. }
  70. #endif /* __NR_fadvise64_64 */
  71. #endif /* __UCLIBC_HAS_LFS__ */