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

source code of glibc/stdio-common/bug3.c