pwritev2.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Linux implementation of pwritev2.
  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. ssize_t
  19. pwritev2 (int fd, const struct iovec *vector, int count, off_t offset,
  20. int flags)
  21. {
  22. # ifdef __NR_pwritev2
  23. ssize_t result = SYSCALL_CANCEL (pwritev2, fd, vector, count,
  24. LO_HI_LONG (offset), flags);
  25. if (result >= 0 || errno != ENOSYS)
  26. return result;
  27. # endif
  28. /* Trying to emulate the pwritev2 syscall flags is troublesome:
  29. * We can not temporary change the file state of the O_DSYNC and O_SYNC
  30. flags to emulate RWF_{D}SYNC (attempts to change the state of using
  31. fcntl are silently ignored).
  32. * IOCB_HIPRI requires the file opened in O_DIRECT and uses an internal
  33. semantic not provided by any other flag (O_NONBLOCK for instance). */
  34. if (flags != 0)
  35. {
  36. __set_errno (ENOTSUP);
  37. return -1;
  38. }
  39. if (offset == -1)
  40. return __writev (fd, vector, count);
  41. else
  42. return pwritev (fd, vector, count, offset);
  43. }
  44. #endif