Back to index

glibc  2.9
bug4.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <unistd.h>
00003 #include <string.h>
00004 
00005 int stdio_block_read = 1, stdio_block_write = 1;
00006 
00007 int
00008 main (int argc, char *argv[])
00009 {
00010   FILE *f;
00011   int i;
00012   char buffer[31];
00013   const char filename[] = "/tmp/bug4.test";
00014 
00015   while ((i = getopt (argc, argv, "rw")) != -1)
00016     switch (i)
00017       {
00018       case 'r':
00019        stdio_block_read = 0;
00020        break;
00021       case 'w':
00022        stdio_block_write = 0;
00023        break;
00024       }
00025 
00026   f = fopen (filename, "w+");
00027   for (i = 0; i < 9000; ++i)
00028     putc('x', f);
00029 
00030   fseek (f, 8180L, 0);
00031   fwrite ("Where does this text come from?", 1, 31, f);
00032   fseek (f, 8180L, 0);
00033   fread (buffer, 1, 31, f);
00034   fwrite (buffer, 1, 31, stdout);
00035   fclose (f);
00036   remove (filename);
00037 
00038   if (!memcmp (buffer, "Where does this text come from?", 31))
00039     {
00040       puts ("\nTest succeeded.");
00041       return 0;
00042     }
00043   else
00044     {
00045       puts ("\nTest FAILED!");
00046       return 1;
00047     }
00048 }