1 | #include <stdio.h> |
2 | #include <unistd.h> |
3 | #include <string.h> |
4 | |
5 | int stdio_block_read = 1, stdio_block_write = 1; |
6 | |
7 | int |
8 | main (int argc, char *argv[]) |
9 | { |
10 | FILE *f; |
11 | int i; |
12 | char buffer[31]; |
13 | const char filename[] = OBJPFX "bug4.test" ; |
14 | |
15 | while ((i = getopt (argc: argc, argv: argv, shortopts: "rw" )) != -1) |
16 | switch (i) |
17 | { |
18 | case 'r': |
19 | stdio_block_read = 0; |
20 | break; |
21 | case 'w': |
22 | stdio_block_write = 0; |
23 | break; |
24 | } |
25 | |
26 | f = fopen (filename, "w+" ); |
27 | for (i = 0; i < 9000; ++i) |
28 | putc(c: 'x', stream: f); |
29 | |
30 | fseek (f, 8180L, 0); |
31 | fwrite ("Where does this text come from?" , 1, 31, f); |
32 | fseek (f, 8180L, 0); |
33 | fread (ptr: buffer, size: 1, n: 31, stream: f); |
34 | fwrite (buffer, 1, 31, stdout); |
35 | fclose (f); |
36 | remove (filename); |
37 | |
38 | if (!memcmp (buffer, "Where does this text come from?" , 31)) |
39 | { |
40 | puts (s: "\nTest succeeded." ); |
41 | return 0; |
42 | } |
43 | else |
44 | { |
45 | puts (s: "\nTest FAILED!" ); |
46 | return 1; |
47 | } |
48 | } |
49 | |