update from main archive 960919
[platform/upstream/linaro-glibc.git] / stdio-common / bug5.c
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 <ansidecl.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10
11 static char buf[8192];
12
13 int
14 DEFUN_VOID(main)
15 {
16   FILE *in;
17   FILE *out;
18   static char inname[] = "/tmp/bug5.in";
19   static char outname[] = "/tmp/bug5.out";
20   char *printbuf;
21   int i, 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, "%d\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 (getc (in), out);
42   i = fread (buf, 1, sizeof (buf), 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 ("There should be no further output from this test.");
57   fflush (stdout);
58
59   asprintf (&printbuf, "cmp %s %s", inname, outname);
60   result = system (printbuf);
61   remove (inname);
62   remove (outname);
63
64   exit ((result != 0));
65 }