* sysdeps/mach/hurd/i386/tls.h (THREAD_DTV): Changed type of _DTV
[glibc.git] / stdio-common / bug7.c
blob2b1efe3bc616384f32fb276c16739ab0d464cfde
1 /* Regression test for fseek and freopen bugs. */
3 #include <stdio.h>
5 int
6 main (int argc, char *argv[])
8 int lose = 0;
9 char filename[L_tmpnam];
10 FILE *fp;
12 if (tmpnam (filename) == NULL)
14 printf ("tmpnam failed\n");
15 lose = 1;
17 else
19 fp = fopen (filename, "w+");
20 fprintf (fp, "Hello world!\n");
21 fflush (fp);
22 fseek (fp, 5L, SEEK_SET);
23 if (fseek (fp, -1L, SEEK_CUR) < 0)
25 printf ("seek failed\n");
26 lose = 1;
28 fclose (fp);
29 remove (filename);
33 FILE *file1;
34 FILE *file2;
35 char filename1[L_tmpnam];
36 char filename2[L_tmpnam];
37 int ch;
39 if (tmpnam (filename1) == NULL || tmpnam (filename2) == NULL)
41 printf ("tmpnam failed\n");
42 lose = 1;
44 else
47 file1 = fopen (filename1, "w");
48 fclose (file1);
50 file2 = fopen (filename2, "w");
51 fputc ('x', file2);
52 fclose (file2);
54 file1 = fopen (filename1, "r");
55 file2 = freopen (filename2, "r", file1);
56 if ((ch = fgetc (file2)) != 'x')
58 printf ("wrong character in reopened file, value = %d\n", ch);
59 lose = 1;
61 fclose (file2);
62 remove (filename1);
63 remove (filename2);
67 puts (lose ? "Test FAILED!" : "Test succeeded.");
68 return lose;