Thu Jun 27 02:49:28 1996 Ulrich Drepper <drepper@cygnus.com>
[glibc/history.git] / stdio-common / bug7.c
blobaf06f8d6a5a4b0b69c6b162531e70030e4f6435a
1 /* Regression test for fseek and freopen bugs. */
3 #include <stdio.h>
5 int
6 main ()
8 int lose = 0;
9 char filename[] = "/tmp/foo";
10 FILE *fp;
12 fp = fopen (filename, "w+");
13 fprintf (fp, "Hello world!\n");
14 fflush (fp);
15 fseek (fp, 5L, SEEK_SET);
16 if (fseek (fp, -1L, SEEK_CUR) < 0)
18 printf ("seek failed\n");
19 lose = 1;
21 fclose (fp);
22 remove (filename);
25 FILE *file1;
26 FILE *file2;
27 char filename1[] = "/tmp/foo";
28 char filename2[] = "/tmp/bar";
29 int ch;
31 file1 = fopen (filename1, "w");
32 fclose (file1);
34 file2 = fopen (filename2, "w");
35 fputc ('x', file2);
36 fclose (file2);
38 file1 = fopen (filename1, "r");
39 file2 = freopen (filename2, "r", file1);
40 if ((ch = fgetc (file2)) != 'x')
42 printf ("wrong character in reopened file, value = %d\n", ch);
43 lose = 1;
45 fclose (file1);
46 fclose (file2);
47 remove (filename1);
48 remove (filename2);
51 puts (lose ? "Test FAILED!" : "Test succeeded.");
52 return lose;