posix_fadvise64.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 advise)
  24. {
  25. if (len != (off_t) len)
  26. return EOVERFLOW;
  27. INTERNAL_SYSCALL_DECL (err);
  28. int ret = INTERNAL_SYSCALL (posix_fadvise64, err, 6, fd, 0,
  29. __LONG_LONG_PAIR ((long) (offset >> 32), (long) offset),
  30. (off_t) len, advise);
  31. if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
  32. return 0;
  33. return INTERNAL_SYSCALL_ERRNO (ret, err);
  34. }
  35. /* 32 bit implementation is kind of a pita */
  36. #elif __WORDSIZE == 32
  37. int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advise)
  38. {
  39. INTERNAL_SYSCALL_DECL (err);
  40. int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd, advise,
  41. __LONG_LONG_PAIR((long) (offset >> 32), (long) offset ),
  42. __LONG_LONG_PAIR((long) (len >> 32), (long) len));
  43. if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
  44. return 0;
  45. return INTERNAL_SYSCALL_ERRNO (ret, err);
  46. }
  47. #else
  48. #error your machine is neither 32 bit or 64 bit ... it must be magical
  49. #endif
  50. #endif /* __NR_fadvise64_64 */
  51. #endif /* __UCLIBC_HAS_LFS__ */