update from main archive 970203
[glibc/history.git] / stdio-common / bug5.c
blob59fb6bb9d972c252a0fc4268d5586887a55bdfba
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 <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
10 static char buf[8192];
12 int
13 main (void)
15 FILE *in;
16 FILE *out;
17 static char inname[] = "/tmp/bug5.in";
18 static char outname[] = "/tmp/bug5.out";
19 char *printbuf;
20 size_t i;
21 int result;
23 /* Create a test file. */
24 in = fopen (inname, "w+");
25 if (in == NULL)
27 perror (inname);
28 return 1;
30 for (i = 0; i < 1000; ++i)
31 fprintf (in, "%u\n", i);
33 out = fopen (outname, "w");
34 if (out == NULL)
36 perror (outname);
37 return 1;
39 if (fseek (in, 0L, SEEK_SET) != 0)
40 abort ();
41 putc (getc (in), out);
42 i = fread (buf, 1, sizeof (buf), in);
43 if (i == 0)
45 perror ("fread");
46 return 1;
48 if (fwrite (buf, 1, i, out) != i)
50 perror ("fwrite");
51 return 1;
53 fclose (in);
54 fclose (out);
56 puts ("There should be no further output from this test.");
57 fflush (stdout);
59 asprintf (&printbuf, "cmp %s %s", inname, outname);
60 result = system (printbuf);
61 remove (inname);
62 remove (outname);
64 exit ((result != 0));