]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
1 | /* Regression test for fseek and freopen bugs. */ |
2 | ||
3 | #include <stdio.h> | |
4 | ||
5 | int | |
11336c16 | 6 | main (int argc, char *argv[]) |
28f540f4 RM |
7 | { |
8 | int lose = 0; | |
9d187dd4 | 9 | char filename[L_tmpnam]; |
28f540f4 | 10 | FILE *fp; |
11336c16 | 11 | |
9d187dd4 | 12 | if (tmpnam (filename) == NULL) |
28f540f4 | 13 | { |
9d187dd4 | 14 | printf ("tmpnam failed\n"); |
28f540f4 RM |
15 | lose = 1; |
16 | } | |
9d187dd4 UD |
17 | else |
18 | { | |
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) | |
24 | { | |
25 | printf ("seek failed\n"); | |
26 | lose = 1; | |
27 | } | |
28 | fclose (fp); | |
29 | remove (filename); | |
30 | } | |
28f540f4 RM |
31 | |
32 | { | |
33 | FILE *file1; | |
34 | FILE *file2; | |
9d187dd4 UD |
35 | char filename1[L_tmpnam]; |
36 | char filename2[L_tmpnam]; | |
28f540f4 RM |
37 | int ch; |
38 | ||
9d187dd4 | 39 | if (tmpnam (filename1) == NULL || tmpnam (filename2) == NULL) |
28f540f4 | 40 | { |
9d187dd4 | 41 | printf ("tmpnam failed\n"); |
28f540f4 RM |
42 | lose = 1; |
43 | } | |
9d187dd4 UD |
44 | else |
45 | { | |
46 | ||
47 | file1 = fopen (filename1, "w"); | |
48 | fclose (file1); | |
49 | ||
50 | file2 = fopen (filename2, "w"); | |
51 | fputc ('x', file2); | |
52 | fclose (file2); | |
53 | ||
54 | file1 = fopen (filename1, "r"); | |
55 | file2 = freopen (filename2, "r", file1); | |
56 | if ((ch = fgetc (file2)) != 'x') | |
57 | { | |
58 | printf ("wrong character in reopened file, value = %d\n", ch); | |
59 | lose = 1; | |
60 | } | |
61 | fclose (file2); | |
62 | remove (filename1); | |
63 | remove (filename2); | |
64 | } | |
28f540f4 RM |
65 | } |
66 | ||
67 | puts (lose ? "Test FAILED!" : "Test succeeded."); | |
68 | return lose; | |
69 | } |