@@ -3490,7 +3490,7 @@ JANET_CORE_FN(janet_cfun_ev_all_tasks,
3490
3490
JANET_CORE_FN (janet_cfun_to_stream ,
3491
3491
"(ev/to-stream file)" ,
3492
3492
"Convert a core/file to a core/stream. On POSIX operating systems, this will mark "
3493
- "the underlying open file description as non-blocking." ) {
3493
+ "the underlying open file descriptor as non-blocking." ) {
3494
3494
janet_fixarity (argc , 1 );
3495
3495
int32_t flags = 0 ;
3496
3496
int32_t stream_flags = 0 ;
@@ -3500,10 +3500,13 @@ JANET_CORE_FN(janet_cfun_to_stream,
3500
3500
if (flags & JANET_FILE_NOT_CLOSEABLE ) stream_flags |= JANET_STREAM_NOT_CLOSEABLE ;
3501
3501
if (flags & JANET_FILE_CLOSED ) janet_panic ("file is closed" );
3502
3502
#ifdef JANET_WINDOWS
3503
- int fno = _fileno (file );
3504
- int dupped_fno = _dup (fno );
3505
- if (dupped_fno == -1 ) janet_panic (janet_strerror (errno ));
3506
- JanetStream * stream = janet_stream (_get_osfhandle (dupped_fno ), stream_flags , NULL );
3503
+ HANDLE handle = (HANDLE ) _get_osfhandle (_fileno (file ));
3504
+ HANDLE prochandle = GetCurrentProcess ();
3505
+ HANDLE dupped_handle = INVALID_HANDLE_VALUE ;
3506
+ if (!DuplicateHandle (prochandle , handle , prochandle , & dupped_handle , 0 , FALSE, DUPLICATE_SAME_ACCESS )) {
3507
+ janet_panic ("cannot duplicate handle to file" );
3508
+ }
3509
+ JanetStream * stream = janet_stream (dupped_handle , stream_flags , NULL );
3507
3510
#else
3508
3511
int handle = fileno (file );
3509
3512
int dupped_handle = 0 ;
0 commit comments