Add UNSUPPORTED check in elf/tst-pldd.
[glibc.git] / stdio-common / bug7.c
blobc9c2ef5139cc2b7c145ff743c57d3ef1d278b2cb
1 /* Regression test for fseek and freopen bugs. */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 int
8 main (int argc, char *argv[])
10 int lose = 0;
11 char filename[] = "/tmp/bug7.XXXXXX";
12 FILE *fp;
14 int fd = mkstemp (filename);
15 if (fd == -1)
17 printf ("mkstemp failed\n");
18 lose = 1;
20 else
22 close (fd);
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)
29 printf ("seek failed\n");
30 lose = 1;
32 fclose (fp);
33 remove (filename);
37 FILE *file1;
38 FILE *file2;
39 char filename1[] = "/tmp/bug7.XXXXXX";
40 char filename2[] = "/tmp/bug7.XXXXXX";
41 int ch;
43 int fd1 = mkstemp (filename1);
44 int fd2 = mkstemp (filename2);
45 if (fd1 == -1 || fd2 == -1)
47 printf ("mkstemp failed\n");
48 lose = 1;
50 else
52 close (fd1);
53 close (fd2);
55 file1 = fopen (filename1, "w");
56 fclose (file1);
58 file2 = fopen (filename2, "w");
59 fputc ('x', file2);
60 fclose (file2);
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);
67 lose = 1;
69 fclose (file2);
70 remove (filename1);
71 remove (filename2);
75 puts (lose ? "Test FAILED!" : "Test succeeded.");
76 return lose;