1#include <stdio.h>
2#include <unistd.h>
3#include <string.h>
4
5#include <support/xstdio.h>
6
7int stdio_block_read = 1, stdio_block_write = 1;
8
9int
10main (int argc, char *argv[])
11{
12 FILE *f;
13 int i;
14 char buffer[31];
15 const char filename[] = OBJPFX "bug4.test";
16
17 while ((i = getopt (argc: argc, argv: argv, shortopts: "rw")) != -1)
18 switch (i)
19 {
20 case 'r':
21 stdio_block_read = 0;
22 break;
23 case 'w':
24 stdio_block_write = 0;
25 break;
26 }
27
28 f = fopen (filename, "w+");
29 for (i = 0; i < 9000; ++i)
30 putc(c: 'x', stream: f);
31
32 fseek (f, 8180L, 0);
33 fwrite ("Where does this text come from?", 1, 31, f);
34 fseek (f, 8180L, 0);
35 xfread (ptr: buffer, size: 1, nmemb: 31, stream: f);
36 fwrite (buffer, 1, 31, stdout);
37 fclose (f);
38 remove (filename);
39
40 if (!memcmp (buffer, "Where does this text come from?", 31))
41 {
42 puts (s: "\nTest succeeded.");
43 return 0;
44 }
45 else
46 {
47 puts (s: "\nTest FAILED!");
48 return 1;
49 }
50}
51

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