summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2018-02-02 10:46:26 +0100
committerFlorian Weimer <fweimer@redhat.com>2018-02-02 10:46:26 +0100
commitd4b4a00a462348750bb18544eb30853ee6ac5d10 (patch)
treeede7a1a13907496496c48e436a5b5dc85be3ac2e /misc
parent84c94d2fd90d84ae7e67657ee8e22c2d1b796f63 (diff)
downloadglibc-d4b4a00a462348750bb18544eb30853ee6ac5d10.tar.gz
preadv2/pwritev2: Handle offset == -1 [BZ #22753]
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'misc')
-rw-r--r--misc/tst-preadvwritev-common.c38
-rw-r--r--misc/tst-preadvwritev2.c1
-rw-r--r--misc/tst-preadvwritev64v2.c1
3 files changed, 40 insertions, 0 deletions
diff --git a/misc/tst-preadvwritev-common.c b/misc/tst-preadvwritev-common.c
index 560c8f89b6..b59a3de465 100644
--- a/misc/tst-preadvwritev-common.c
+++ b/misc/tst-preadvwritev-common.c
@@ -16,6 +16,7 @@
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>
@@ -25,6 +26,7 @@
#include <support/check.h>
#include <support/temp_file.h>
+#include <support/xunistd.h>
static char *temp_filename;
static int temp_fd;
@@ -50,6 +52,42 @@ do_prepare (int argc, char **argv)
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)
{
diff --git a/misc/tst-preadvwritev2.c b/misc/tst-preadvwritev2.c
index d8a9daf66a..be22802dbe 100644
--- a/misc/tst-preadvwritev2.c
+++ b/misc/tst-preadvwritev2.c
@@ -29,6 +29,7 @@ static int
do_test (void)
{
do_test_with_invalid_flags ();
+ do_test_without_offset ();
return do_test_with_offset (0);
}
diff --git a/misc/tst-preadvwritev64v2.c b/misc/tst-preadvwritev64v2.c
index 2c656ae3d7..8d3cc32b28 100644
--- a/misc/tst-preadvwritev64v2.c
+++ b/misc/tst-preadvwritev64v2.c
@@ -31,6 +31,7 @@ static int
do_test (void)
{
do_test_with_invalid_flags ();
+ do_test_without_offset ();
return do_test_with_offset (0);
}