Add missing files
[glibc/history.git] / stdio-common / bug5.c
blob18f069ae291aabffc76245ff6f0f4dcaf816a2a0
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. */
6 #include <ansidecl.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
11 static char buf[8192];
13 int
14 DEFUN_VOID(main)
16 FILE *in;
17 FILE *out;
18 static char inname[] = "/tmp/bug5.in";
19 static char outname[] = "/tmp/bug5.out";
20 int i;
22 /* Create a test file. */
23 in = fopen (inname, "w+");
24 if (in == NULL)
26 perror (inname);
27 return 1;
29 for (i = 0; i < 1000; ++i)
30 fprintf (in, "%d\n", i);
32 out = fopen (outname, "w");
33 if (out == NULL)
35 perror (outname);
36 return 1;
38 if (fseek (in, 0L, SEEK_SET) != 0)
39 abort ();
40 putc (getc (in), out);
41 i = fread (buf, 1, sizeof (buf), in);
42 if (i == 0)
44 perror ("fread");
45 return 1;
47 if (fwrite (buf, 1, i, out) != i)
49 perror ("fwrite");
50 return 1;
52 fclose (in);
53 fclose (out);
55 puts ("There should be no further output from this test.");
56 fflush (stdout);
57 execlp ("cmp", "cmp", inname, outname, (char *) NULL);
58 perror ("execlp: cmp");
59 exit (1);