(fd: libc::c_int, inheritable: bool)
| 513 | // Only used on Windows; Unix automatically sets O_CLOEXEC |
| 514 | #[cfg(windows)] |
| 515 | fn set_inheritable(fd: libc::c_int, inheritable: bool) -> std::io::Result<()> { |
| 516 | use windows_sys::Win32::Foundation::{ |
| 517 | HANDLE, HANDLE_FLAG_INHERIT, INVALID_HANDLE_VALUE, SetHandleInformation, |
| 518 | }; |
| 519 | |
| 520 | let handle = unsafe { libc::get_osfhandle(fd) }; |
| 521 | if handle == INVALID_HANDLE_VALUE as isize { |
| 522 | return Err(std::io::Error::last_os_error()); |
| 523 | } |
| 524 | |
| 525 | let flags = if inheritable { HANDLE_FLAG_INHERIT } else { 0 }; |
| 526 | let result = unsafe { SetHandleInformation(handle as HANDLE, HANDLE_FLAG_INHERIT, flags) }; |
| 527 | if result == 0 { |
| 528 | return Err(std::io::Error::last_os_error()); |
| 529 | } |
| 530 | |
| 531 | Ok(()) |
| 532 | } |
no test coverage detected