posix_fadvise64.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 2003-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <errno.h>
  15. #include <fcntl.h>
  16. #include <shlib-compat.h>
  17. int __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise);
  18. libc_hidden_proto (__posix_fadvise64_l64)
  19. /* Both arm and powerpc implements fadvise64_64 with last 'advise' argument
  20. just after 'fd' to avoid the requirement of implementing 7-arg syscalls.
  21. ARM also defines __NR_fadvise64_64 as __NR_arm_fadvise64_64.
  22. s390 implements fadvice64_64 using a specific struct with arguments
  23. packed inside. This is the only implementation handled in arch-specific
  24. code. */
  25. #ifndef __NR_fadvise64_64
  26. # define __NR_fadvise64_64 __NR_fadvise64
  27. #endif
  28. /* Advice the system about the expected behaviour of the application with
  29. respect to the file associated with FD. */
  30. int
  31. __posix_fadvise64_l64 (int fd, off64_t offset, off64_t len, int advise)
  32. {
  33. INTERNAL_SYSCALL_DECL (err);
  34. #ifdef __ASSUME_FADVISE64_64_6ARG
  35. int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, err, fd, advise,
  36. SYSCALL_LL64 (offset), SYSCALL_LL64 (len));
  37. #else
  38. int ret = INTERNAL_SYSCALL_CALL (fadvise64_64, err, fd,
  39. __ALIGNMENT_ARG SYSCALL_LL64 (offset),
  40. SYSCALL_LL64 (len), advise);
  41. #endif
  42. if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
  43. return 0;
  44. return INTERNAL_SYSCALL_ERRNO (ret, err);
  45. }
  46. /* The type of the len argument was changed from size_t to off_t in
  47. POSIX.1-2003 TC1. */
  48. #ifndef __OFF_T_MATCHES_OFF64_T
  49. # if SHLIB_COMPAT(libc, GLIBC_2_2, GLIBC_2_3_3)
  50. int __posix_fadvise64_l32 (int fd, off64_t offset, size_t len, int advise);
  51. int
  52. attribute_compat_text_section
  53. __posix_fadvise64_l32 (int fd, off64_t offset, size_t len, int advise)
  54. {
  55. return __posix_fadvise64_l64 (fd, offset, len, advise);
  56. }
  57. versioned_symbol (libc, __posix_fadvise64_l64, posix_fadvise64, GLIBC_2_3_3);
  58. compat_symbol (libc, __posix_fadvise64_l32, posix_fadvise64, GLIBC_2_2);
  59. # else
  60. weak_alias (__posix_fadvise64_l64, posix_fadvise64);
  61. # endif
  62. #else
  63. weak_alias (__posix_fadvise64_l64, posix_fadvise64);
  64. strong_alias (__posix_fadvise64_l64, posix_fadvise);
  65. #endif
  66. libc_hidden_def (__posix_fadvise64_l64)