This source file includes following definitions.
- gl_msvc_invalid_parameter_handler
- is_open
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include <errno.h>
20 #include <fcntl.h>
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27
28 #if defined _WIN32 && ! defined __CYGWIN__
29
30 # define WIN32_LEAN_AND_MEAN
31 # include <windows.h>
32 #endif
33
34
35
36
37
38
39 #define BACKUP_STDERR_FILENO 10
40 #define ASSERT_STREAM myerr
41 #include "macros.h"
42
43 static FILE *myerr;
44
45
46 #undef atoi
47 #undef close
48 #undef fcntl
49 #undef fdopen
50 #undef fflush
51 #undef fprintf
52 #undef open
53 #undef read
54 #undef strcasestr
55 #undef strstr
56 #undef write
57 #if defined _WIN32 && !defined __CYGWIN__
58 # define fdopen _fdopen
59 #endif
60
61 #include "qemu.h"
62
63 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER
64 static void __cdecl
65 gl_msvc_invalid_parameter_handler (const wchar_t *expression,
66 const wchar_t *function,
67 const wchar_t *file,
68 unsigned int line,
69 uintptr_t dummy)
70 {
71 }
72 #endif
73
74
75 static int
76 is_open (int fd)
77 {
78 #if defined _WIN32 && ! defined __CYGWIN__
79
80
81
82 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
83 #else
84 # ifndef F_GETFL
85 # error Please port fcntl to your platform
86 # endif
87 return 0 <= fcntl (fd, F_GETFL);
88 #endif
89 }
90
91 int
92 main (int argc, char *argv[])
93 {
94
95
96 myerr = fdopen (BACKUP_STDERR_FILENO, "w");
97 if (!myerr)
98 return 2;
99
100 ASSERT (argc == 2);
101
102 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER
103
104 _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
105 #endif
106
107
108
109 bool is_qemu = is_running_under_qemu_user ();
110
111
112
113
114
115 char buffer[2] = { 's', 't' };
116
117 ASSERT (read (STDIN_FILENO, buffer, 2) == 1);
118
119 buffer[0]++;
120 ASSERT (write (STDOUT_FILENO, buffer, 1) == 1);
121
122 switch (atoi (argv[1]))
123 {
124 case 0:
125
126 ASSERT (is_open (STDERR_FILENO));
127 break;
128 case 1:
129
130
131
132
133 #if !(defined __hpux || (defined _WIN32 && ! defined __CYGWIN__))
134 if (!is_qemu)
135 ASSERT (! is_open (STDERR_FILENO));
136 #endif
137 break;
138 default:
139 ASSERT (0);
140 }
141
142 int fd;
143 for (fd = 3; fd < 7; fd++)
144 if (!(is_qemu && fd == 3))
145 {
146 errno = 0;
147 ASSERT (close (fd) == -1);
148 ASSERT (errno == EBADF);
149 }
150
151 return 0;
152 }