1 /* Regression test for fseek and freopen bugs. */
6 main (int argc, char *argv[])
9 char filename[L_tmpnam];
12 if (tmpnam (filename) == NULL)
14 printf ("tmpnam failed\n");
19 fp = fopen (filename, "w+");
20 fprintf (fp, "Hello world!\n");
22 fseek (fp, 5L, SEEK_SET);
23 if (fseek (fp, -1L, SEEK_CUR) < 0)
25 printf ("seek failed\n");
35 char filename1[L_tmpnam];
36 char filename2[L_tmpnam];
39 if (tmpnam (filename1) == NULL || tmpnam (filename2) == NULL)
41 printf ("tmpnam failed\n");
47 file1 = fopen (filename1, "w");
50 file2 = fopen (filename2, "w");
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);
67 puts (lose ? "Test FAILED!" : "Test succeeded.");