posix_fadvise64.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  24. {
  25. if (len != (off_t) len)
  26. return EOVERFLOW;
  27. INTERNAL_SYSCALL_DECL (err);
  28. int ret = INTERNAL_SYSCALL (posix_fadvise64, err, 5, fd,
  29. __LONG_LONG_PAIR ((long) (offset >> 32),
  30. (long) offset),
  31. (off_t) len, advice);
  32. if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
  33. return 0;
  34. return INTERNAL_SYSCALL_ERRNO (ret, err);
  35. }
  36. /* 32 bit implementation is kind of a pita */
  37. #elif __WORDSIZE == 32
  38. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  39. {
  40. INTERNAL_SYSCALL_DECL (err);
  41. int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd,
  42. __LONG_LONG_PAIR(offset >> 32, offset & 0xffffffff),
  43. __LONG_LONG_PAIR(len >> 32, len & 0xffffffff),
  44. advice);
  45. if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
  46. return 0;
  47. return INTERNAL_SYSCALL_ERRNO (ret, err);
  48. }
  49. #else
  50. #error your machine is neither 32 bit or 64 bit ... it must be magical
  51. #endif
  52. #elif !defined __NR_fadvise64 && defined __UCLIBC_HAS_STUBS__
  53. /* This is declared as a strong alias in posix_fadvise.c if __NR_fadvise64
  54. * is defined.
  55. */
  56. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
  57. {
  58. return ENOSYS;
  59. }
  60. #endif /* __NR_fadvise64_64 */
  61. #endif /* __UCLIBC_HAS_LFS__ */