(root)/
glibc-2.38/
stdio-common/
bug4.c
       1  #include <stdio.h>
       2  #include <unistd.h>
       3  #include <string.h>
       4  
       5  #include <support/xstdio.h>
       6  
       7  int stdio_block_read = 1, stdio_block_write = 1;
       8  
       9  int
      10  main (int argc, char *argv[])
      11  {
      12    FILE *f;
      13    int i;
      14    char buffer[31];
      15    const char filename[] = OBJPFX "bug4.test";
      16  
      17    while ((i = getopt (argc, argv, "rw")) != -1)
      18      switch (i)
      19        {
      20        case 'r':
      21  	stdio_block_read = 0;
      22  	break;
      23        case 'w':
      24  	stdio_block_write = 0;
      25  	break;
      26        }
      27  
      28    f = fopen (filename, "w+");
      29    for (i = 0; i < 9000; ++i)
      30      putc('x', f);
      31  
      32    fseek (f, 8180L, 0);
      33    fwrite ("Where does this text come from?", 1, 31, f);
      34    fseek (f, 8180L, 0);
      35    xfread (buffer, 1, 31, f);
      36    fwrite (buffer, 1, 31, stdout);
      37    fclose (f);
      38    remove (filename);
      39  
      40    if (!memcmp (buffer, "Where does this text come from?", 31))
      41      {
      42        puts ("\nTest succeeded.");
      43        return 0;
      44      }
      45    else
      46      {
      47        puts ("\nTest FAILED!");
      48        return 1;
      49      }
      50  }