Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / linux / sys-preadv_pwritev.c
blobf5087dddcc85bce0d4b5a8eebfc416b494ae0c60
1 #define _GNU_SOURCE
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <sys/stat.h>
6 #include <unistd.h>
7 #include <sys/syscall.h>
8 #include <sys/uio.h>
9 #include <string.h>
10 #include "../../memcheck.h"
12 #include <errno.h>
14 int main(int argc, char **argv)
16 char str0[] = "hello ";
17 char str1[] = "world\n";
18 struct iovec iov[2];
19 int fd;
21 fd = open("prwv_source", O_CREAT | O_RDWR, 0644);
22 if (fd == -1) {
23 perror("prwv2_source");
24 exit(EXIT_FAILURE);
27 iov[0].iov_base = str0;
28 iov[0].iov_len = strlen(str0);
29 iov[1].iov_base = str1;
30 iov[1].iov_len = strlen(str1);
32 /* Check pwritev and preadv called with the correct arguments works. */
33 if (pwritev(fd, iov, 2, 0) == -1) {
34 perror("pwritev");
35 exit(EXIT_FAILURE);
38 if (preadv(fd, iov, 2, 0) == -1) {
39 perror("preadv");
40 printf("errno: %d\n", errno);
41 exit(EXIT_FAILURE);
44 /* Check valgrind will produce expected warnings for the
45 various wrong arguments. */
46 do {
47 /* always allocate 16 bytes to not to have different .exps for different reg sizes */
48 char *mem = malloc(16);
49 void *t = (void *) &mem[0];
50 void *z = (void *) -1;
51 int c = *((int *) &mem[4]);
52 pwritev(fd, NULL, 2, 0);
53 pwritev(fd, z, 2, 0);
54 pwritev(fd, t, 2, 0);
55 pwritev(fd, iov, -1, 0);
56 pwritev(fd, iov, c, 0);
57 pwritev(fd, iov, 2, -5);
58 pwritev(-1, iov, 2, -5);
60 preadv(fd, NULL, 2, 0);
61 preadv(fd, z, 2, 0);
62 preadv(fd, t, 2, 0);
63 preadv(fd, iov, -1, 0);
64 preadv(fd, iov, c, 0);
65 preadv(fd, iov, 2, -5);
66 preadv(-1, iov, 2, -5);
68 iov[1].iov_base = (void *) -1;
69 pwritev(fd, iov, 2, 0);
70 preadv(fd, iov, 2, 0);
71 free(mem);
72 } while (0);
74 close(fd);
75 unlink("prwv_source");
76 exit(EXIT_SUCCESS);