posix_fadvise64.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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-2005 by Erik Andersen <andersen@codepoet.org>
  7. *
  8. * GNU Library General Public License (LGPL) version 2 or later.
  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. #define __NR___syscall_fadvise64_64 __NR_fadvise64_64
  21. /* 64 bit implementation is cake ... or more like pie ... */
  22. #if __WORDSIZE == 64
  23. _syscall4(int, __syscall_fadvise64_64, int, fd, __off64_t, offset,
  24. __off64_t, len, int, advice);
  25. int __libc_posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  26. {
  27. return (__syscall_fadvise64_64(fd, offset, len, advice));
  28. }
  29. weak_alias(__libc_posix_fadvise64, posix_fadvise64);
  30. /* 32 bit implementation is kind of a pita */
  31. #elif __WORDSIZE == 32
  32. #ifdef _syscall6 /* workaround until everyone has _syscall6() */
  33. _syscall6(int, __syscall_fadvise64_64, int, fd,
  34. unsigned long, high_offset, unsigned long, low_offset,
  35. unsigned long, high_len, unsigned long, low_len,
  36. int, advice);
  37. int __libc_posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  38. {
  39. return (__syscall_fadvise64_64(fd,
  40. __LONG_LONG_PAIR(offset >> 32, offset & 0xffffffff),
  41. __LONG_LONG_PAIR(len >> 32, len & 0xffffffff),
  42. advice));
  43. }
  44. weak_alias(__libc_posix_fadvise64, posix_fadvise64);
  45. #else
  46. #warning _syscall6 has not been defined for your machine :(
  47. #endif /* _syscall6 */
  48. #else
  49. #error your machine is neither 32 bit or 64 bit ... it must be magical
  50. #endif
  51. #elif !defined __NR_fadvise64
  52. /* This is declared as a weak alias in posix_fadvice.c if __NR_fadvise64
  53. * is defined.
  54. */
  55. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  56. {
  57. __set_errno(ENOSYS);
  58. return -1;
  59. }
  60. #endif /* __NR_fadvise64_64 */
  61. #endif /* __UCLIBC_HAS_LFS__ */