]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdio-common/bug7.c
[powerpc] No need to enter "Ignore Exceptions Mode"
[thirdparty/glibc.git] / stdio-common / bug7.c
CommitLineData
28f540f4
RM
1/* Regression test for fseek and freopen bugs. */
2
3#include <stdio.h>
5c112f1b
JM
4#include <stdlib.h>
5#include <unistd.h>
28f540f4
RM
6
7int
11336c16 8main (int argc, char *argv[])
28f540f4
RM
9{
10 int lose = 0;
5c112f1b 11 char filename[] = "/tmp/bug7.XXXXXX";
28f540f4 12 FILE *fp;
11336c16 13
5c112f1b
JM
14 int fd = mkstemp (filename);
15 if (fd == -1)
28f540f4 16 {
5c112f1b 17 printf ("mkstemp failed\n");
28f540f4
RM
18 lose = 1;
19 }
9d187dd4
UD
20 else
21 {
5c112f1b 22 close (fd);
9d187dd4
UD
23 fp = fopen (filename, "w+");
24 fprintf (fp, "Hello world!\n");
25 fflush (fp);
26 fseek (fp, 5L, SEEK_SET);
27 if (fseek (fp, -1L, SEEK_CUR) < 0)
28 {
29 printf ("seek failed\n");
30 lose = 1;
31 }
32 fclose (fp);
33 remove (filename);
34 }
28f540f4
RM
35
36 {
37 FILE *file1;
38 FILE *file2;
5c112f1b
JM
39 char filename1[] = "/tmp/bug7.XXXXXX";
40 char filename2[] = "/tmp/bug7.XXXXXX";
28f540f4
RM
41 int ch;
42
5c112f1b
JM
43 int fd1 = mkstemp (filename1);
44 int fd2 = mkstemp (filename2);
45 if (fd1 == -1 || fd2 == -1)
28f540f4 46 {
5c112f1b 47 printf ("mkstemp failed\n");
28f540f4
RM
48 lose = 1;
49 }
9d187dd4
UD
50 else
51 {
5c112f1b
JM
52 close (fd1);
53 close (fd2);
9d187dd4
UD
54
55 file1 = fopen (filename1, "w");
56 fclose (file1);
57
58 file2 = fopen (filename2, "w");
59 fputc ('x', file2);
60 fclose (file2);
61
62 file1 = fopen (filename1, "r");
63 file2 = freopen (filename2, "r", file1);
64 if ((ch = fgetc (file2)) != 'x')
65 {
66 printf ("wrong character in reopened file, value = %d\n", ch);
67 lose = 1;
68 }
69 fclose (file2);
70 remove (filename1);
71 remove (filename2);
72 }
28f540f4
RM
73 }
74
75 puts (lose ? "Test FAILED!" : "Test succeeded.");
76 return lose;
77}