1 #include <stdio.h>
2 #include <string.h>
3 
4 char x[4096], z[4096], b[21], m[4096 * 4];
5 
6 int
main(void)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 (m, 4096 * 4 - 10, 1, f);
24   fread (b, 20, 1, f);
25   printf ("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 (b, 20, 1, f);
31   printf ("got %s (should be %s)\n", b, "zzzzzzzzzzzzzzzzzzzz");
32   if (strcmp (b, "zzzzzzzzzzzzzzzzzzzz"))
33     failed = 1;
34 
35   fread (b, 20, 1, f);
36   printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx");
37   if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx"))
38     failed = 1;
39 
40   fread (b, 20, 1, f);
41   printf ("got %s (should be %s)\n", b, "xxxxxxxxxxxxxxxxxxxx");
42   if (strcmp (b, "xxxxxxxxxxxxxxxxxxxx"))
43     failed = 1;
44 
45   return failed;
46 }
47