summaryrefslogtreecommitdiff
path: root/stdio/bug3.c
blob: 1684720b9fd8e2f22e1f24201118d2674c2310fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <ansidecl.h>
#include <stdio.h>
#include <string.h>

int
DEFUN_VOID(main)
{
  FILE *f;
  int i;

  f = fopen("/tmp/bugtest", "w+");
  for (i=0; i<9000; i++)
    putc ('x', f);
  fseek (f, 8180L, 0);
  fwrite ("Where does this text go?", 1, 24, f);
  fflush (f);

  rewind (f);
  for (i=0; i<9000; i++)
    {
      int j;

      if ((j = getc(f)) != 'x')
	{
	  if (i != 8180)
	    {
	      printf ("Test FAILED!");
	      return 1;
	    }
	  else
	    {
	      char buf[25];

	      buf[0] = j;
	      fread (buf + 1, 1, 23, f);
	      buf[24] = '\0';
	      if (strcmp (buf, "Where does this text go?") != 0)
		{
		  printf ("%s\nTest FAILED!\n", buf);
		  return 1;
		}
	      i += 23;
	    }
	}
    }

  fclose(f);

  puts ("Test succeeded.");

  return 0;
}