1 /* Common definitions for preadv and pwritev.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
22 static void do_prepare (void);
23 #define PREPARE(argc, argv) do_prepare ()
24 static int do_test (void);
25 #define TEST_FUNCTION do_test ()
26 #include "test-skeleton.c"
28 static char *temp_filename
;
34 temp_fd
= create_temp_file ("tst-preadvwritev.", &temp_filename
);
37 printf ("cannot create temporary file: %m\n");
43 do { printf ("error: %s (line %d)\n", str, __LINE__); return 1; } while (0)
46 do_test_with_offset (off_t offset
)
54 memset (buf1
, 0xf0, sizeof buf1
);
55 memset (buf2
, 0x0f, sizeof buf2
);
57 /* Write two buffer with 32 and 64 bytes respectively. */
58 memset (iov
, 0, sizeof iov
);
59 iov
[0].iov_base
= buf1
;
60 iov
[0].iov_len
= sizeof buf1
;
61 iov
[1].iov_base
= buf2
;
62 iov
[1].iov_len
= sizeof buf2
;
64 ret
= pwritev (temp_fd
, iov
, 2, offset
);
66 FAIL ("first pwritev returned -1");
67 if (ret
!= (sizeof buf1
+ sizeof buf2
))
68 FAIL ("first pwritev returned an unexpected value");
70 ret
= pwritev (temp_fd
, iov
, 2, sizeof buf1
+ sizeof buf2
+ offset
);
72 FAIL ("second pwritev returned -1");
73 if (ret
!= (sizeof buf1
+ sizeof buf2
))
74 FAIL ("second pwritev returned an unexpected value");
79 memset (buf3
, 0x0f, sizeof buf3
);
80 memset (buf4
, 0xf0, sizeof buf4
);
82 iov
[0].iov_base
= buf3
;
83 iov
[0].iov_len
= sizeof buf3
;
84 iov
[1].iov_base
= buf4
;
85 iov
[1].iov_len
= sizeof buf4
;
87 /* Now read two buffer with 32 and 64 bytes respectively. */
88 ret
= preadv (temp_fd
, iov
, 2, offset
);
90 FAIL ("first preadv returned -1");
91 if (ret
!= (sizeof buf3
+ sizeof buf4
))
92 FAIL ("first preadv returned an unexpected value");
94 if (memcmp (buf1
, buf3
, sizeof buf1
) != 0)
95 FAIL ("first buffer from first preadv different than expected");
96 if (memcmp (buf2
, buf4
, sizeof buf2
) != 0)
97 FAIL ("second buffer from first preadv different than expected");
99 ret
= preadv (temp_fd
, iov
, 2, sizeof buf3
+ sizeof buf4
+ offset
);
101 FAIL ("second preadv returned -1");
102 if (ret
!= (sizeof buf3
+ sizeof buf4
))
103 FAIL ("second preadv returned an unexpected value");
105 /* And compare the buffers read and written to check if there are equal. */
106 if (memcmp (buf1
, buf3
, sizeof buf1
) != 0)
107 FAIL ("first buffer from second preadv different than expected");
108 if (memcmp (buf2
, buf4
, sizeof buf2
) != 0)
109 FAIL ("second buffer from second preadv different than expected");