1 | #include <stdio.h> |
2 | #include <string.h> |
3 | |
4 | char x[4096], z[4096], b[21], m[4096 * 4]; |
5 | |
6 | int |
7 | main (void) |
8 | { |
9 | FILE *f = tmpfile (); |
10 | int i, failed = 0; |
11 | |
12 | memset (x, 'x', 4096); |
13 | memset (z, 'z', 4096); |
14 | b[20] = 0; |
15 | |
16 | for (i = 0; i <= 5; i++) |
17 | { |
18 | fwrite (x, 4096, 1, f); |
19 | fwrite (z, 4096, 1, f); |
20 | } |
21 | rewind (f); |
22 | |
23 | fread (ptr: m, size: 4096 * 4 - 10, n: 1, stream: f); |
24 | fread (ptr: b, size: 20, n: 1, stream: f); |
25 | printf (format: "got %s (should be %s)\n" , b, "zzzzzzzzzzxxxxxxxxxx" ); |
26 | if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx" )) |
27 | failed = 1; |
28 | |
29 | fseek (f, -40, SEEK_CUR); |
30 | fread (ptr: b, size: 20, n: 1, stream: f); |
31 | printf (format: "got %s (should be %s)\n" , b, "zzzzzzzzzzzzzzzzzzzz" ); |
32 | if (strcmp (b, "zzzzzzzzzzzzzzzzzzzz" )) |
33 | failed = 1; |
34 | |
35 | fread (ptr: b, size: 20, n: 1, stream: f); |
36 | printf (format: "got %s (should be %s)\n" , b, "zzzzzzzzzzxxxxxxxxxx" ); |
37 | if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx" )) |
38 | failed = 1; |
39 | |
40 | fread (ptr: b, size: 20, n: 1, stream: f); |
41 | printf (format: "got %s (should be %s)\n" , b, "xxxxxxxxxxxxxxxxxxxx" ); |
42 | if (strcmp (b, "xxxxxxxxxxxxxxxxxxxx" )) |
43 | failed = 1; |
44 | |
45 | return failed; |
46 | } |
47 | |