1#include <stdio.h>
2#include <string.h>
3
4#include <support/xstdio.h>
5
6int
7main (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 (c: 'x', stream: 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(stream: f)) != 'x')
26 {
27 if (i != 8180)
28 {
29 printf (format: "Test FAILED!");
30 return 1;
31 }
32 else
33 {
34 char buf[25];
35
36 buf[0] = j;
37 xfread (ptr: buf + 1, size: 1, nmemb: 23, stream: f);
38 buf[24] = '\0';
39 if (strcmp (buf, "Where does this text go?") != 0)
40 {
41 printf (format: "%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 (s: "Test succeeded.");
53
54 return 0;
55}
56

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