Back to index

glibc  2.9
bug12.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 
00004 char x[4096], z[4096], b[21], m[4096 * 4];
00005 
00006 int
00007 main (void)
00008 {
00009   FILE *f = tmpfile ();
00010   int i, failed = 0;
00011 
00012   memset (x, 'x', 4096);
00013   memset (z, 'z', 4096);
00014   b[20] = 0;
00015 
00016   for (i = 0; i <= 5; i++)
00017     {
00018       fwrite (x, 4096, 1, f);
00019       fwrite (z, 4096, 1, f);
00020     }
00021   rewind (f);
00022 
00023   fread (m, 4096 * 4 - 10, 1, f);
00024   fread (b, 20, 1, f);
00025   printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx");
00026   if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx"))
00027     failed = 1;
00028 
00029   fseek (f, -40, SEEK_CUR);
00030   fread (b, 20, 1, f);
00031   printf ("got %s (should be %s)\n", b, "zzzzzzzzzzzzzzzzzzzz");
00032   if (strcmp (b, "zzzzzzzzzzzzzzzzzzzz"))
00033     failed = 1;
00034 
00035   fread (b, 20, 1, f);
00036   printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx");
00037   if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx"))
00038     failed = 1;
00039 
00040   fread (b, 20, 1, f);
00041   printf ("got %s (should be %s)\n", b, "xxxxxxxxxxxxxxxxxxxx");
00042   if (strcmp (b, "xxxxxxxxxxxxxxxxxxxx"))
00043     failed = 1;
00044 
00045   return failed;
00046 }