1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* |
3 | * Author: SeongJae Park <sj@kernel.org> |
4 | */ |
5 | |
6 | #include <fcntl.h> |
7 | #include <stdlib.h> |
8 | #include <unistd.h> |
9 | #include <stdio.h> |
10 | |
11 | #pragma GCC diagnostic push |
12 | #if __GNUC__ >= 11 && __GNUC_MINOR__ >= 1 |
13 | /* Ignore read(2) overflow and write(2) overread compile warnings */ |
14 | #pragma GCC diagnostic ignored "-Wstringop-overread" |
15 | #pragma GCC diagnostic ignored "-Wstringop-overflow" |
16 | #endif |
17 | |
18 | void write_read_with_huge_count(char *file) |
19 | { |
20 | int filedesc = open(file, O_RDWR); |
21 | char buf[25]; |
22 | int ret; |
23 | |
24 | printf("%s %s\n" , __func__, file); |
25 | if (filedesc < 0) { |
26 | fprintf(stderr, "failed opening %s\n" , file); |
27 | exit(1); |
28 | } |
29 | |
30 | write(filedesc, "" , 0xfffffffful); |
31 | perror("after write: " ); |
32 | ret = read(filedesc, buf, 0xfffffffful); |
33 | perror("after read: " ); |
34 | close(filedesc); |
35 | } |
36 | |
37 | #pragma GCC diagnostic pop |
38 | |
39 | int main(int argc, char *argv[]) |
40 | { |
41 | if (argc != 2) { |
42 | fprintf(stderr, "Usage: %s <file>\n" , argv[0]); |
43 | exit(1); |
44 | } |
45 | write_read_with_huge_count(file: argv[1]); |
46 | |
47 | return 0; |
48 | } |
49 | |