1/* If stdio is working correctly, after this is run infile and outfile
2 will have the same contents. If the bug (found in GNU C library 0.3)
3 exhibits itself, outfile will be missing the 2nd through 1023rd
4 characters. */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <unistd.h>
9
10static char buf[8192];
11
12int
13main (void)
14{
15 FILE *in;
16 FILE *out;
17 static char inname[] = OBJPFX "bug5test.in";
18 static char outname[] = OBJPFX "bug5test.out";
19 char *printbuf;
20 size_t i;
21 int result;
22
23 /* Create a test file. */
24 in = fopen (inname, "w+");
25 if (in == NULL)
26 {
27 perror (inname);
28 return 1;
29 }
30 for (i = 0; i < 1000; ++i)
31 fprintf (in, "%Zu\n", i);
32
33 out = fopen (outname, "w");
34 if (out == NULL)
35 {
36 perror (outname);
37 return 1;
38 }
39 if (fseek (in, 0L, SEEK_SET) != 0)
40 abort ();
41 putc (c: getc (stream: in), stream: out);
42 i = fread (ptr: buf, size: 1, n: sizeof (buf), stream: in);
43 if (i == 0)
44 {
45 perror ("fread");
46 return 1;
47 }
48 if (fwrite (buf, 1, i, out) != i)
49 {
50 perror ("fwrite");
51 return 1;
52 }
53 fclose (in);
54 fclose (out);
55
56 puts (s: "There should be no further output from this test.");
57 fflush (stdout);
58
59 /* We must remove this entry to assure the `cmp' binary does not use
60 the perhaps incompatible new shared libraries. */
61 unsetenv (name: "LD_LIBRARY_PATH");
62
63 asprintf (ptr: &printbuf, fmt: "cmp %s %s", inname, outname);
64 result = system (command: printbuf);
65 remove (inname);
66 remove (outname);
67
68 exit ((result != 0));
69}
70

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