This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22 #include "stdio--.h"
23
24
25 #include <unistd.h>
26
27
28
29
30
31 #define BACKUP_STDERR_FILENO 10
32 #define ASSERT_STREAM myerr
33 #include "macros.h"
34
35 static FILE *myerr;
36
37 int
38 main (void)
39 {
40 FILE *fp;
41
42
43 if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
44 || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
45 return 2;
46
47 {
48 FILE *tmp;
49 ASSERT (tmp = fopen ("/dev/null", "r"));
50 ASSERT (STDERR_FILENO < fileno (tmp));
51 ASSERT (fp = fopen ("/dev/null", "w"));
52 ASSERT (fileno (tmp) < fileno (fp));
53 ASSERT (fclose (tmp) == 0);
54 }
55
56
57 ASSERT (freopen ("/dev/null", "r+", fp) == fp);
58 ASSERT (STDERR_FILENO < fileno (fp));
59
60 ASSERT (freopen ("/dev/null", "r", stdin) == stdin);
61 ASSERT (STDIN_FILENO == fileno (stdin));
62
63 ASSERT (freopen ("/dev/null", "w", stdout) == stdout);
64 ASSERT (STDOUT_FILENO == fileno (stdout));
65
66 ASSERT (freopen ("/dev/null", "w", stderr) == stderr);
67 ASSERT (STDERR_FILENO == fileno (stderr));
68
69
70 ASSERT (close (STDIN_FILENO) == 0);
71
72 ASSERT (freopen ("/dev/null", "w", stdout) == stdout);
73 ASSERT (STDOUT_FILENO == fileno (stdout));
74
75 ASSERT (freopen ("/dev/null", "w", stderr) == stderr);
76 ASSERT (STDERR_FILENO == fileno (stderr));
77
78 ASSERT (freopen ("/dev/null", "a", fp) == fp);
79 ASSERT (STDERR_FILENO < fileno (fp));
80
81
82 ASSERT (close (STDOUT_FILENO) == 0);
83
84 ASSERT (freopen ("/dev/null", "w", stderr) == stderr);
85 ASSERT (STDERR_FILENO == fileno (stderr));
86
87 ASSERT (freopen ("/dev/null", "a+", fp) == fp);
88 ASSERT (STDERR_FILENO < fileno (fp));
89
90
91 ASSERT (close (STDERR_FILENO) == 0);
92
93 ASSERT (freopen ("/dev/null", "w+", fp) == fp);
94 ASSERT (STDERR_FILENO < fileno (fp));
95
96 return 0;
97 }