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 | |
10 | #include <support/support.h> |
11 | |
12 | static char buf[8192]; |
13 | |
14 | int |
15 | main (void) |
16 | { |
17 | FILE *in; |
18 | FILE *out; |
19 | static char inname[] = OBJPFX "bug5test.in" ; |
20 | static char outname[] = OBJPFX "bug5test.out" ; |
21 | char *printbuf; |
22 | size_t i; |
23 | int result; |
24 | |
25 | /* Create a test file. */ |
26 | in = fopen (inname, "w+" ); |
27 | if (in == NULL) |
28 | { |
29 | perror (inname); |
30 | return 1; |
31 | } |
32 | for (i = 0; i < 1000; ++i) |
33 | fprintf (in, "%Zu\n" , i); |
34 | |
35 | out = fopen (outname, "w" ); |
36 | if (out == NULL) |
37 | { |
38 | perror (outname); |
39 | return 1; |
40 | } |
41 | if (fseek (in, 0L, SEEK_SET) != 0) |
42 | abort (); |
43 | putc (c: getc (stream: in), stream: out); |
44 | i = fread (ptr: buf, size: 1, n: sizeof (buf), stream: in); |
45 | if (i == 0) |
46 | { |
47 | perror ("fread" ); |
48 | return 1; |
49 | } |
50 | if (fwrite (buf, 1, i, out) != i) |
51 | { |
52 | perror ("fwrite" ); |
53 | return 1; |
54 | } |
55 | fclose (in); |
56 | fclose (out); |
57 | |
58 | puts (s: "There should be no further output from this test." ); |
59 | fflush (stdout); |
60 | |
61 | /* We must remove this entry to assure the `cmp' binary does not use |
62 | the perhaps incompatible new shared libraries. */ |
63 | unsetenv (name: "LD_LIBRARY_PATH" ); |
64 | |
65 | printbuf = xasprintf (format: "cmp %s %s" , inname, outname); |
66 | result = system (command: printbuf); |
67 | remove (inname); |
68 | remove (outname); |
69 | |
70 | exit ((result != 0)); |
71 | } |
72 | |