(root)/
glibc-2.38/
stdio-common/
bug3.c
       1  #include <stdio.h>
       2  #include <string.h>
       3  
       4  #include <support/xstdio.h>
       5  
       6  int
       7  main (void)
       8  {
       9    FILE *f;
      10    int i;
      11    const char filename[] = OBJPFX "bug3.test";
      12  
      13    f = fopen(filename, "w+");
      14    for (i=0; i<9000; i++)
      15      putc ('x', f);
      16    fseek (f, 8180L, 0);
      17    fwrite ("Where does this text go?", 1, 24, f);
      18    fflush (f);
      19  
      20    rewind (f);
      21    for (i=0; i<9000; i++)
      22      {
      23        int j;
      24  
      25        if ((j = getc(f)) != 'x')
      26  	{
      27  	  if (i != 8180)
      28  	    {
      29  	      printf ("Test FAILED!");
      30  	      return 1;
      31  	    }
      32  	  else
      33  	    {
      34  	      char buf[25];
      35  
      36  	      buf[0] = j;
      37  	      xfread (buf + 1, 1, 23, f);
      38  	      buf[24] = '\0';
      39  	      if (strcmp (buf, "Where does this text go?") != 0)
      40  		{
      41  		  printf ("%s\nTest FAILED!\n", buf);
      42  		  return 1;
      43  		}
      44  	      i += 23;
      45  	    }
      46  	}
      47      }
      48  
      49    fclose(f);
      50    remove(filename);
      51  
      52    puts ("Test succeeded.");
      53  
      54    return 0;
      55  }