+2018-02-02 Florian Weimer <fweimer@redhat.com>
+
+ [BZ #22753]
+ * sysdeps/posix/preadv2.c (preadv2): Handle offset == -1.
+ * sysdeps/posix/preadv64v2.c (preadv64v2): Likewise.
+ * sysdeps/posix/pwritev2.c (pwritev2): Likewise.
+ * sysdeps/posix/pwritev64v2.c (pwritev64v2): Likweise.
+ * sysdeps/unix/sysv/linux/preadv2.c (preadv2): Likewise.
+ * sysdeps/unix/sysv/linux/preadv64v2.c (preadv64v2): Likewise.
+ * sysdeps/unix/sysv/linux/pwritev2.c (pwritev2): Likewise.
+ * sysdeps/unix/sysv/linux/pwritev64v2.c (pwritev64v2): Likweise.
+ * manual/llio.texi (Scatter-Gather): Mention offset -1.
+ * misc/tst-preadvwritev-common.c (do_test_without_offset): New.
+ * misc/tst-preadvwritev2.c (do_test): Call it.
+ * misc/tst-preadvwritev64v2.c (do_test): Likewise.
+
2018-02-02 Siddhesh Poyarekar <siddhesh@sourceware.org>
* sysdeps/aarch64/memcmp.S: Use L() macro for labels.
@c This is a syscall for Linux v4.6. The sysdeps/posix fallback emulation
@c is also MT-Safe since it calls preadv.
-This function is similar to the @code{preadv} function, with the difference
-it adds an extra @var{flags} parameter of type @code{int}. The supported
-@var{flags} are dependent of the underlying system. For Linux it supports:
+This function is similar to the @code{preadv} function, with the
+difference it adds an extra @var{flags} parameter of type @code{int}.
+Additionally, if @var{offset} is @math{-1}, the current file position
+is used and updated (like the @code{readv} function).
+
+The supported @var{flags} are dependent of the underlying system. For
+Linux it supports:
@vtable @code
@item RWF_HIPRI
@c This is a syscall for Linux v4.6. The sysdeps/posix fallback emulation
@c is also MT-Safe since it calls pwritev.
-This function is similar to the @code{pwritev} function, with the difference
-it adds an extra @var{flags} parameter of type @code{int}. The supported
-@var{flags} are dependent of the underlying system and for Linux it supports
-the same ones as for @code{preadv2}.
+This function is similar to the @code{pwritev} function, with the
+difference it adds an extra @var{flags} parameter of type @code{int}.
+Additionally, if @var{offset} is @math{-1}, the current file position
+should is used and updated (like the @code{writev} function).
+
+The supported @var{flags} are dependent of the underlying system. For
+Linux, the supported flags are the same as those for @code{preadv2}.
When the source file is compiled with @code{_FILE_OFFSET_BITS == 64} the
@code{pwritev2} function is in fact @code{pwritev64v2} and the type
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <array_length.h>
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <support/check.h>
#include <support/temp_file.h>
+#include <support/xunistd.h>
static char *temp_filename;
static int temp_fd;
pwritev (__fd, __iov, __iovcnt, __offset)
#endif
+static __attribute__ ((unused)) void
+do_test_without_offset (void)
+{
+ xftruncate (temp_fd, 0);
+
+ xwrite (temp_fd, "123", 3);
+ xlseek (temp_fd, 2, SEEK_SET);
+ {
+ struct iovec iov[] =
+ {
+ { (void *) "abc", 3 },
+ { (void *) "xyzt", 4 },
+ };
+ TEST_COMPARE (PWRITEV (temp_fd, iov, array_length (iov), -1), 7);
+ }
+ TEST_COMPARE (xlseek (temp_fd, 0, SEEK_CUR), 9);
+
+ xlseek (temp_fd, 1, SEEK_SET);
+ char buf1[3];
+ char buf2[2];
+ {
+ struct iovec iov[] =
+ {
+ { buf1, sizeof (buf1) },
+ { buf2, sizeof (buf2) },
+ };
+ TEST_COMPARE (PREADV (temp_fd, iov, array_length (iov), -1),
+ sizeof (buf1) + sizeof (buf2));
+ TEST_COMPARE (memcmp ("2ab", buf1, sizeof (buf1)), 0);
+ TEST_COMPARE (memcmp ("cx", buf2, sizeof (buf2)), 0);
+ TEST_COMPARE (xlseek (temp_fd, 0, SEEK_CUR), 6);
+ }
+
+ xftruncate (temp_fd, 0);
+}
+
static int
do_test_with_offset (off_t offset)
{
do_test (void)
{
do_test_with_invalid_flags ();
+ do_test_without_offset ();
return do_test_with_offset (0);
}
do_test (void)
{
do_test_with_invalid_flags ();
+ do_test_without_offset ();
return do_test_with_offset (0);
}
return -1;
}
- return preadv (fd, vector, count, offset);
+ if (offset == -1)
+ return __readv (fd, vector, count);
+ else
+ return preadv (fd, vector, count, offset);
}
#endif
return -1;
}
- return preadv64 (fd, vector, count, offset);
+ if (offset == -1)
+ return __readv (fd, vector, count);
+ else
+ return preadv64 (fd, vector, count, offset);
}
#ifdef __OFF_T_MATCHES_OFF64_T
return -1;
}
- return pwritev (fd, vector, count, offset);
+ if (offset == -1)
+ return __writev (fd, vector, count);
+ else
+ return pwritev (fd, vector, count, offset);
}
#endif
return -1;
}
- return pwritev64 (fd, vector, count, offset);
+ if (offset == -1)
+ return __writev (fd, vector, count);
+ else
+ return pwritev64 (fd, vector, count, offset);
}
#ifdef __OFF_T_MATCHES_OFF64_T
__set_errno (ENOTSUP);
return -1;
}
- return preadv (fd, vector, count, offset);
+ if (offset == -1)
+ return __readv (fd, vector, count);
+ else
+ return preadv (fd, vector, count, offset);
}
#endif
__set_errno (ENOTSUP);
return -1;
}
- return preadv64 (fd, vector, count, offset);
+
+ if (offset == -1)
+ return __readv (fd, vector, count);
+ else
+ return preadv64 (fd, vector, count, offset);
}
#ifdef __OFF_T_MATCHES_OFF64_T
__set_errno (ENOTSUP);
return -1;
}
- return pwritev (fd, vector, count, offset);
+ if (offset == -1)
+ return __writev (fd, vector, count);
+ else
+ return pwritev (fd, vector, count, offset);
}
#endif
__set_errno (ENOTSUP);
return -1;
}
- return pwritev64 (fd, vector, count, offset);
+ if (offset == -1)
+ return __writev (fd, vector, count);
+ else
+ return pwritev64 (fd, vector, count, offset);
}
#ifdef __OFF_T_MATCHES_OFF64_T