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

source code of glibc/stdio-common/bug12.c