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/>. */
26 #include <support/check.h>
27 #include <support/temp_file.h>
29 static char *temp_filename
;
32 static int do_test (void);
35 do_prepare (int argc
, char **argv
)
37 temp_fd
= create_temp_file ("tst-preadvwritev.", &temp_filename
);
39 FAIL_EXIT1 ("cannot create temporary file");
41 #define PREPARE do_prepare
44 # define PREADV(__fd, __iov, __iovcnt, __offset) \
45 preadv (__fd, __iov, __iovcnt, __offset)
49 # define PWRITEV(__fd, __iov, __iovcnt, __offset) \
50 pwritev (__fd, __iov, __iovcnt, __offset)
54 do_test_with_offset (off_t offset
)
62 memset (buf1
, 0xf0, sizeof buf1
);
63 memset (buf2
, 0x0f, sizeof buf2
);
65 /* Write two buffer with 32 and 64 bytes respectively. */
66 memset (iov
, 0, sizeof iov
);
67 iov
[0].iov_base
= buf1
;
68 iov
[0].iov_len
= sizeof buf1
;
69 iov
[1].iov_base
= buf2
;
70 iov
[1].iov_len
= sizeof buf2
;
72 ret
= PWRITEV (temp_fd
, iov
, 2, offset
);
74 FAIL_RET ("first pwritev returned -1");
75 if (ret
!= (sizeof buf1
+ sizeof buf2
))
76 FAIL_RET ("first pwritev returned an unexpected value");
78 ret
= PWRITEV (temp_fd
, iov
, 2, sizeof buf1
+ sizeof buf2
+ offset
);
80 FAIL_RET ("second pwritev returned -1");
81 if (ret
!= (sizeof buf1
+ sizeof buf2
))
82 FAIL_RET ("second pwritev returned an unexpected value");
87 memset (buf3
, 0x0f, sizeof buf3
);
88 memset (buf4
, 0xf0, sizeof buf4
);
90 iov
[0].iov_base
= buf3
;
91 iov
[0].iov_len
= sizeof buf3
;
92 iov
[1].iov_base
= buf4
;
93 iov
[1].iov_len
= sizeof buf4
;
95 /* Now read two buffer with 32 and 64 bytes respectively. */
96 ret
= PREADV (temp_fd
, iov
, 2, offset
);
98 FAIL_RET ("first preadv returned -1");
99 if (ret
!= (sizeof buf3
+ sizeof buf4
))
100 FAIL_RET ("first preadv returned an unexpected value");
102 if (memcmp (buf1
, buf3
, sizeof buf1
) != 0)
103 FAIL_RET ("first buffer from first preadv different than expected");
104 if (memcmp (buf2
, buf4
, sizeof buf2
) != 0)
105 FAIL_RET ("second buffer from first preadv different than expected");
107 ret
= PREADV (temp_fd
, iov
, 2, sizeof buf3
+ sizeof buf4
+ offset
);
109 FAIL_RET ("second preadv returned -1");
110 if (ret
!= (sizeof buf3
+ sizeof buf4
))
111 FAIL_RET ("second preadv returned an unexpected value");
113 /* And compare the buffers read and written to check if there are equal. */
114 if (memcmp (buf1
, buf3
, sizeof buf1
) != 0)
115 FAIL_RET ("first buffer from second preadv different than expected");
116 if (memcmp (buf2
, buf4
, sizeof buf2
) != 0)
117 FAIL_RET ("second buffer from second preadv different than expected");
122 #include <support/test-driver.c>