1 | // RUN: %clangxx -O0 %s -D_FILE_OFFSET_BITS=64 -o %t |
2 | |
3 | // REQUIRES: glibc |
4 | |
5 | #ifndef _GNU_SOURCE |
6 | # define _GNU_SOURCE |
7 | #endif |
8 | #include <assert.h> |
9 | #include <fcntl.h> |
10 | #include <stdlib.h> |
11 | #include <sys/syscall.h> |
12 | #include <unistd.h> |
13 | |
14 | #if !defined(__GLIBC_PREREQ) |
15 | # define __GLIBC_PREREQ(a, b) 0 |
16 | #endif |
17 | |
18 | #if !__GLIBC_PREREQ(2, 27) |
19 | # define copy_file_range(a, b, c, d, e, f) \ |
20 | (ssize_t) syscall(__NR_copy_file_range, a, b, c, d, e, f) |
21 | #endif |
22 | |
23 | int main(void) { |
24 | int fdin = open(file: "/proc/self/maps" , O_RDONLY); |
25 | assert(fdin > 0); |
26 | char tmp[] = "/tmp/map.XXXXXX" ; |
27 | int fdout = mkstemp(template: tmp); |
28 | assert(fdout > 0); |
29 | off_t offin = -1, offout = 0; |
30 | ssize_t cpy = copy_file_range(infd: fdin, pinoff: &offin, outfd: fdout, poutoff: &offout, length: 8, flags: 0); |
31 | assert(cpy < 0); |
32 | offin = 0; |
33 | offout = 16; |
34 | cpy = copy_file_range(infd: fdin, pinoff: &offin, outfd: fdout, poutoff: &offout, length: 8, flags: 0); |
35 | assert(cpy < 0); |
36 | offout = 0; |
37 | cpy = copy_file_range(infd: fdin, pinoff: &offin, outfd: fdout, poutoff: &offout, length: 8, flags: 0); |
38 | assert(cpy == 8); |
39 | close(fd: fdout); |
40 | close(fd: fdin); |
41 | return 0; |
42 | } |
43 | |