@@ -53,7 +53,7 @@ static void print_err_msg(const char* expect, ssize_t expect_len,
53
53
fprintf (stderr , "\n" );
54
54
}
55
55
56
- static void tty_alloc (uv_handle_t * ttyin_fd , size_t size , uv_buf_t * buf ) {
56
+ static void tty_alloc (uv_handle_t * handle , size_t size , uv_buf_t * buf ) {
57
57
buf -> base = malloc (size );
58
58
ASSERT (buf -> base != NULL );
59
59
buf -> len = size ;
@@ -133,23 +133,26 @@ static void make_key_event_records(WORD virt_key, DWORD ctr_key_state,
133
133
134
134
TEST_IMPL (tty_duplicate_vt100_fn_key ) {
135
135
int r ;
136
- uv_os_fd_t ttyin_fd ;
136
+ int ttyin_fd ;
137
137
uv_tty_t tty_in ;
138
138
uv_loop_t * loop ;
139
+ HANDLE handle ;
139
140
INPUT_RECORD records [2 ];
140
141
DWORD written ;
141
142
142
143
loop = uv_default_loop ();
143
144
144
145
/* Make sure we have an FD that refers to a tty */
145
- ttyin_fd = CreateFileA ("conin$" ,
146
- GENERIC_READ | GENERIC_WRITE ,
147
- FILE_SHARE_READ | FILE_SHARE_WRITE ,
148
- NULL ,
149
- OPEN_EXISTING ,
150
- FILE_ATTRIBUTE_NORMAL ,
151
- NULL );
152
- ASSERT (ttyin_fd != INVALID_HANDLE_VALUE );
146
+ handle = CreateFileA ("conin$" ,
147
+ GENERIC_READ | GENERIC_WRITE ,
148
+ FILE_SHARE_READ | FILE_SHARE_WRITE ,
149
+ NULL ,
150
+ OPEN_EXISTING ,
151
+ FILE_ATTRIBUTE_NORMAL ,
152
+ NULL );
153
+ ASSERT (handle != INVALID_HANDLE_VALUE );
154
+ ttyin_fd = _open_osfhandle ((intptr_t ) handle , 0 );
155
+ ASSERT (ttyin_fd >= 0 );
153
156
ASSERT (UV_TTY == uv_guess_handle (ttyin_fd ));
154
157
155
158
r = uv_tty_init (uv_default_loop (), & tty_in , ttyin_fd , 1 ); /* Readable. */
@@ -172,7 +175,7 @@ TEST_IMPL(tty_duplicate_vt100_fn_key) {
172
175
* duplicate.
173
176
*/
174
177
make_key_event_records (VK_F1 , 0 , TRUE, records );
175
- WriteConsoleInputW (ttyin_fd , records , ARRAY_SIZE (records ), & written );
178
+ WriteConsoleInputW (handle , records , ARRAY_SIZE (records ), & written );
176
179
ASSERT (written == ARRAY_SIZE (records ));
177
180
178
181
uv_run (loop , UV_RUN_DEFAULT );
@@ -183,24 +186,27 @@ TEST_IMPL(tty_duplicate_vt100_fn_key) {
183
186
184
187
TEST_IMPL (tty_duplicate_alt_modifier_key ) {
185
188
int r ;
186
- uv_os_fd_t ttyin_fd ;
189
+ int ttyin_fd ;
187
190
uv_tty_t tty_in ;
188
191
uv_loop_t * loop ;
192
+ HANDLE handle ;
189
193
INPUT_RECORD records [2 ];
190
194
INPUT_RECORD alt_records [2 ];
191
195
DWORD written ;
192
196
193
197
loop = uv_default_loop ();
194
198
195
199
/* Make sure we have an FD that refers to a tty */
196
- ttyin_fd = CreateFileA ("conin$" ,
197
- GENERIC_READ | GENERIC_WRITE ,
198
- FILE_SHARE_READ | FILE_SHARE_WRITE ,
199
- NULL ,
200
- OPEN_EXISTING ,
201
- FILE_ATTRIBUTE_NORMAL ,
202
- NULL );
203
- ASSERT (ttyin_fd != INVALID_HANDLE_VALUE );
200
+ handle = CreateFileA ("conin$" ,
201
+ GENERIC_READ | GENERIC_WRITE ,
202
+ FILE_SHARE_READ | FILE_SHARE_WRITE ,
203
+ NULL ,
204
+ OPEN_EXISTING ,
205
+ FILE_ATTRIBUTE_NORMAL ,
206
+ NULL );
207
+ ASSERT (handle != INVALID_HANDLE_VALUE );
208
+ ttyin_fd = _open_osfhandle ((intptr_t ) handle , 0 );
209
+ ASSERT (ttyin_fd >= 0 );
204
210
ASSERT (UV_TTY == uv_guess_handle (ttyin_fd ));
205
211
206
212
r = uv_tty_init (uv_default_loop (), & tty_in , ttyin_fd , 1 ); /* Readable. */
@@ -220,22 +226,22 @@ TEST_IMPL(tty_duplicate_alt_modifier_key) {
220
226
221
227
/* Emulate transmission of M-a at normal console */
222
228
make_key_event_records (VK_MENU , 0 , TRUE, alt_records );
223
- WriteConsoleInputW (ttyin_fd , & alt_records [0 ], 1 , & written );
229
+ WriteConsoleInputW (handle , & alt_records [0 ], 1 , & written );
224
230
ASSERT (written == 1 );
225
231
make_key_event_records (L'A' , LEFT_ALT_PRESSED , FALSE, records );
226
- WriteConsoleInputW (ttyin_fd , records , ARRAY_SIZE (records ), & written );
232
+ WriteConsoleInputW (handle , records , ARRAY_SIZE (records ), & written );
227
233
ASSERT (written == 2 );
228
- WriteConsoleInputW (ttyin_fd , & alt_records [1 ], 1 , & written );
234
+ WriteConsoleInputW (handle , & alt_records [1 ], 1 , & written );
229
235
ASSERT (written == 1 );
230
236
231
237
/* Emulate transmission of M-a at WSL(#2111) */
232
238
make_key_event_records (VK_MENU , 0 , TRUE, alt_records );
233
- WriteConsoleInputW (ttyin_fd , & alt_records [0 ], 1 , & written );
239
+ WriteConsoleInputW (handle , & alt_records [0 ], 1 , & written );
234
240
ASSERT (written == 1 );
235
241
make_key_event_records (L'A' , LEFT_ALT_PRESSED , TRUE, records );
236
- WriteConsoleInputW (ttyin_fd , records , ARRAY_SIZE (records ), & written );
242
+ WriteConsoleInputW (handle , records , ARRAY_SIZE (records ), & written );
237
243
ASSERT (written == 2 );
238
- WriteConsoleInputW (ttyin_fd , & alt_records [1 ], 1 , & written );
244
+ WriteConsoleInputW (handle , & alt_records [1 ], 1 , & written );
239
245
ASSERT (written == 1 );
240
246
241
247
uv_run (loop , UV_RUN_DEFAULT );
@@ -246,24 +252,27 @@ TEST_IMPL(tty_duplicate_alt_modifier_key) {
246
252
247
253
TEST_IMPL (tty_composing_character ) {
248
254
int r ;
249
- uv_os_fd_t ttyin_fd ;
255
+ int ttyin_fd ;
250
256
uv_tty_t tty_in ;
251
257
uv_loop_t * loop ;
258
+ HANDLE handle ;
252
259
INPUT_RECORD records [2 ];
253
260
INPUT_RECORD alt_records [2 ];
254
261
DWORD written ;
255
262
256
263
loop = uv_default_loop ();
257
264
258
265
/* Make sure we have an FD that refers to a tty */
259
- ttyin_fd = CreateFileA ("conin$" ,
260
- GENERIC_READ | GENERIC_WRITE ,
261
- FILE_SHARE_READ | FILE_SHARE_WRITE ,
262
- NULL ,
263
- OPEN_EXISTING ,
264
- FILE_ATTRIBUTE_NORMAL ,
265
- NULL );
266
- ASSERT (ttyin_fd != INVALID_HANDLE_VALUE );
266
+ handle = CreateFileA ("conin$" ,
267
+ GENERIC_READ | GENERIC_WRITE ,
268
+ FILE_SHARE_READ | FILE_SHARE_WRITE ,
269
+ NULL ,
270
+ OPEN_EXISTING ,
271
+ FILE_ATTRIBUTE_NORMAL ,
272
+ NULL );
273
+ ASSERT (handle != INVALID_HANDLE_VALUE );
274
+ ttyin_fd = _open_osfhandle ((intptr_t ) handle , 0 );
275
+ ASSERT (ttyin_fd >= 0 );
267
276
ASSERT (UV_TTY == uv_guess_handle (ttyin_fd ));
268
277
269
278
r = uv_tty_init (uv_default_loop (), & tty_in , ttyin_fd , 1 ); /* Readable. */
@@ -284,20 +293,20 @@ TEST_IMPL(tty_composing_character) {
284
293
/* Emulate EUR inputs by LEFT ALT+NUMPAD ASCII KeyComos */
285
294
make_key_event_records (VK_MENU , 0 , FALSE, alt_records );
286
295
alt_records [1 ].Event .KeyEvent .uChar .UnicodeChar = EUR_UNICODE ;
287
- WriteConsoleInputW (ttyin_fd , & alt_records [0 ], 1 , & written );
296
+ WriteConsoleInputW (handle , & alt_records [0 ], 1 , & written );
288
297
make_key_event_records (VK_NUMPAD0 , LEFT_ALT_PRESSED , FALSE, records );
289
- WriteConsoleInputW (ttyin_fd , records , ARRAY_SIZE (records ), & written );
298
+ WriteConsoleInputW (handle , records , ARRAY_SIZE (records ), & written );
290
299
ASSERT (written == ARRAY_SIZE (records ));
291
300
make_key_event_records (VK_NUMPAD1 , LEFT_ALT_PRESSED , FALSE, records );
292
- WriteConsoleInputW (ttyin_fd , records , ARRAY_SIZE (records ), & written );
301
+ WriteConsoleInputW (handle , records , ARRAY_SIZE (records ), & written );
293
302
ASSERT (written == ARRAY_SIZE (records ));
294
303
make_key_event_records (VK_NUMPAD2 , LEFT_ALT_PRESSED , FALSE, records );
295
- WriteConsoleInputW (ttyin_fd , records , ARRAY_SIZE (records ), & written );
304
+ WriteConsoleInputW (handle , records , ARRAY_SIZE (records ), & written );
296
305
ASSERT (written == ARRAY_SIZE (records ));
297
306
make_key_event_records (VK_NUMPAD8 , LEFT_ALT_PRESSED , FALSE, records );
298
- WriteConsoleInputW (ttyin_fd , records , ARRAY_SIZE (records ), & written );
307
+ WriteConsoleInputW (handle , records , ARRAY_SIZE (records ), & written );
299
308
ASSERT (written == ARRAY_SIZE (records ));
300
- WriteConsoleInputW (ttyin_fd , & alt_records [1 ], 1 , & written );
309
+ WriteConsoleInputW (handle , & alt_records [1 ], 1 , & written );
301
310
302
311
uv_run (loop , UV_RUN_DEFAULT );
303
312
0 commit comments