preadv2.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Linux implementation of preadv2.
  2. Copyright (C) 2017-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sys/uio.h>
  16. #include <sysdep-cancel.h>
  17. #ifndef __OFF_T_MATCHES_OFF64_T
  18. # if !defined (__NR_preadv2) && defined (__NR_pread64v2)
  19. # define __NR_preadv2 __NR_pread64v2
  20. # endif
  21. ssize_t
  22. preadv2 (int fd, const struct iovec *vector, int count, off_t offset,
  23. int flags)
  24. {
  25. # ifdef __NR_preadv2
  26. ssize_t result = SYSCALL_CANCEL (preadv2, fd, vector, count,
  27. LO_HI_LONG (offset), flags);
  28. if (result >= 0 || errno != ENOSYS)
  29. return result;
  30. # endif
  31. /* Trying to emulate the preadv2 syscall flags is troublesome:
  32. * We can not temporary change the file state of the O_DSYNC and O_SYNC
  33. flags to emulate RWF_{D}SYNC (attempts to change the state of using
  34. fcntl are silently ignored).
  35. * IOCB_HIPRI requires the file opened in O_DIRECT and uses an internal
  36. semantic not provided by any other flag (O_NONBLOCK for instance). */
  37. if (flags != 0)
  38. {
  39. __set_errno (ENOTSUP);
  40. return -1;
  41. }
  42. if (offset == -1)
  43. return __readv (fd, vector, count);
  44. else
  45. return preadv (fd, vector, count, offset);
  46. }
  47. #endif