Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / linux / sys-copy_file_range.c
blob3022fa1c5ce81482e9979784c18176c2d286c2cc
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 "../../memcheck.h"
9 int main(int argc, char **argv)
11 int fd_in, fd_out;
12 struct stat stat;
13 loff_t len, ret;
15 fd_in = open("copy_file_range_source", O_CREAT | O_RDWR, 0644);
16 if (fd_in == -1) {
17 perror("open copy_file_range_source");
18 exit(EXIT_FAILURE);
21 if (write(fd_in, "foo bar\n", 8) != 8) {
22 perror("writing to the copy_file_range_source");
23 exit(EXIT_FAILURE);
25 lseek(fd_in, 0, SEEK_SET);
27 if (fstat(fd_in, &stat) == -1) {
28 perror("fstat");
29 exit(EXIT_FAILURE);
32 len = stat.st_size;
34 fd_out = open("copy_file_range_dest", O_CREAT | O_WRONLY | O_TRUNC, 0644);
35 if (fd_out == -1) {
36 perror("open copy_file_range_dest");
37 exit(EXIT_FAILURE);
40 /* Check copy_file_range called with the correct arguments works. */
41 do {
42 ret = copy_file_range(fd_in, NULL, fd_out, NULL, len, 0);
43 if (ret == -1) {
44 perror("copy_file_range");
45 exit(EXIT_FAILURE);
48 len -= ret;
49 } while (len > 0);
51 /* Check valgrind will produce expected warnings for the
52 various wrong arguments. */
53 do {
54 void *t = 0; VALGRIND_MAKE_MEM_UNDEFINED (&t, sizeof (void *));
55 void *z = (void *) -1;
57 ret = copy_file_range(fd_in, t, fd_out, NULL, len, 0);
58 ret = copy_file_range(fd_in, NULL, fd_out, z, len, 0);
59 ret = copy_file_range(- 1, NULL, - 1, NULL, len, 0);
60 } while (0);
62 close(fd_in);
63 close(fd_out);
64 unlink("copy_file_range_source");
65 unlink("copy_file_range_dest");
66 exit(EXIT_SUCCESS);