Back to index

glibc  2.9
bug3.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 
00004 int
00005 main (void)
00006 {
00007   FILE *f;
00008   int i;
00009   const char filename[] = "/tmp/bug3.test";
00010 
00011   f = fopen(filename, "w+");
00012   for (i=0; i<9000; i++)
00013     putc ('x', f);
00014   fseek (f, 8180L, 0);
00015   fwrite ("Where does this text go?", 1, 24, f);
00016   fflush (f);
00017 
00018   rewind (f);
00019   for (i=0; i<9000; i++)
00020     {
00021       int j;
00022 
00023       if ((j = getc(f)) != 'x')
00024        {
00025          if (i != 8180)
00026            {
00027              printf ("Test FAILED!");
00028              return 1;
00029            }
00030          else
00031            {
00032              char buf[25];
00033 
00034              buf[0] = j;
00035              fread (buf + 1, 1, 23, f);
00036              buf[24] = '\0';
00037              if (strcmp (buf, "Where does this text go?") != 0)
00038               {
00039                 printf ("%s\nTest FAILED!\n", buf);
00040                 return 1;
00041               }
00042              i += 23;
00043            }
00044        }
00045     }
00046 
00047   fclose(f);
00048   remove(filename);
00049 
00050   puts ("Test succeeded.");
00051 
00052   return 0;
00053 }