1 /* Regression test for fseek and freopen bugs. */
8 main (int argc
, char *argv
[])
11 char filename
[] = "/tmp/bug7.XXXXXX";
14 int fd
= mkstemp (filename
);
17 printf ("mkstemp failed\n");
23 fp
= fopen (filename
, "w+");
24 fprintf (fp
, "Hello world!\n");
26 fseek (fp
, 5L, SEEK_SET
);
27 if (fseek (fp
, -1L, SEEK_CUR
) < 0)
29 printf ("seek failed\n");
39 char filename1
[] = "/tmp/bug7.XXXXXX";
40 char filename2
[] = "/tmp/bug7.XXXXXX";
43 int fd1
= mkstemp (filename1
);
44 int fd2
= mkstemp (filename2
);
45 if (fd1
== -1 || fd2
== -1)
47 printf ("mkstemp failed\n");
55 file1
= fopen (filename1
, "w");
58 file2
= fopen (filename2
, "w");
62 file1
= fopen (filename1
, "r");
63 file2
= freopen (filename2
, "r", file1
);
64 if ((ch
= fgetc (file2
)) != 'x')
66 printf ("wrong character in reopened file, value = %d\n", ch
);
75 puts (lose
? "Test FAILED!" : "Test succeeded.");