Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / linux / sys-preadv2_pwritev2.c
blob942eab68b6adc869a6473fe7639b9340402139c4
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("prwv2_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 pwritev2 and preadv2 called with the correct arguments works. */
33 if (pwritev2(fd, iov, 2, 0, 0) == -1) {
34 perror("pwritev2");
35 exit(EXIT_FAILURE);
38 if (preadv2(fd, iov, 2, 0, 0) == -1) {
39 perror("preadv2");
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 int flag = *((int *) &mem[8]);
53 pwritev2(fd, NULL, 2, 0, 0);
54 pwritev2(fd, z, 2, 0, 0);
55 pwritev2(fd, t, 2, 0, 0);
56 pwritev2(fd, iov, -1, 0, 0);
57 pwritev2(fd, iov, c, 0, 0);
58 pwritev2(fd, iov, 2, -5, 0);
59 pwritev2(-1, iov, 2, -5, 0);
60 pwritev2(fd, iov, 2, -5, flag);
62 preadv2(fd, NULL, 2, 0, 0);
63 preadv2(fd, z, 2, 0, 0);
64 preadv2(fd, t, 2, 0, 0);
65 preadv2(fd, iov, -1, 0, 0);
66 preadv2(fd, iov, c, 0, 0);
67 preadv2(fd, iov, 2, -5, 0);
68 preadv2(-1, iov, 2, -5, 0);
70 iov[1].iov_base = (void *) -1;
71 pwritev2(fd, iov, 2, 0, 0);
72 preadv2(fd, iov, 2, 0, 0);
73 free(mem);
74 } while (0);
76 close(fd);
77 unlink("prwv2_source");
78 exit(EXIT_SUCCESS);