(root)/
glibc-2.38/
stdio-common/
bug12.c
       1  #include <stdio.h>
       2  #include <string.h>
       3  
       4  #include <support/xstdio.h>
       5  
       6  char x[4096], z[4096], b[21], m[4096 * 4];
       7  
       8  int
       9  main (void)
      10  {
      11    FILE *f = tmpfile ();
      12    int i, failed = 0;
      13  
      14    memset (x, 'x', 4096);
      15    memset (z, 'z', 4096);
      16    b[20] = 0;
      17  
      18    for (i = 0; i <= 5; i++)
      19      {
      20        fwrite (x, 4096, 1, f);
      21        fwrite (z, 4096, 1, f);
      22      }
      23    rewind (f);
      24  
      25    xfread (m, 4096 * 4 - 10, 1, f);
      26    xfread (b, 20, 1, f);
      27    printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx");
      28    if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx"))
      29      failed = 1;
      30  
      31    fseek (f, -40, SEEK_CUR);
      32    xfread (b, 20, 1, f);
      33    printf ("got %s (should be %s)\n", b, "zzzzzzzzzzzzzzzzzzzz");
      34    if (strcmp (b, "zzzzzzzzzzzzzzzzzzzz"))
      35      failed = 1;
      36  
      37    xfread (b, 20, 1, f);
      38    printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx");
      39    if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx"))
      40      failed = 1;
      41  
      42    xfread (b, 20, 1, f);
      43    printf ("got %s (should be %s)\n", b, "xxxxxxxxxxxxxxxxxxxx");
      44    if (strcmp (b, "xxxxxxxxxxxxxxxxxxxx"))
      45      failed = 1;
      46  
      47    return failed;
      48  }