* Add partial impl of determine_type_rights fn * Add draft of fd_fdstat_get hostcall * Add writev wrapper for writing IoVec in RawHandle * Move IoVec and writev to separate helper crate * Add Win error handling Clean up closing and duplicating RawHandle * Wrap Win file type result * Add draft impl of fd_close and fd_read * Refactor getting file access rights * Remove winapi from the main Cargo.toml * Add very rough draft of open_path (very incomplete) * Clean up WinError with macro * Ignore dir handle in openat if path absolute * Decode oflags and advance open_path hostcall * Clean up AccessRight and FlagsAndAttributes flags * Implement path_get (without symlink expansion yet!) * Add ShareMode and fix path_get for nested paths * Add some error mappings between Win and WASI * Clean up fdflags conversions * Fix sharing violation when calling openat at '.' * Apply Alex's fix of using ManuallyDrop instead forget * Clean up * Explicitly specify workspace to avoid comp errors at tests
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
#![allow(non_camel_case_types)]
|
|
use crate::{winerror, Result};
|
|
use std::os::windows::prelude::RawHandle;
|
|
use winapi::shared::minwindef::FALSE;
|
|
|
|
pub fn dup(old_handle: RawHandle) -> Result<RawHandle> {
|
|
use winapi::um::handleapi::DuplicateHandle;
|
|
use winapi::um::processthreadsapi::GetCurrentProcess;
|
|
use winapi::um::winnt::DUPLICATE_SAME_ACCESS;
|
|
unsafe {
|
|
let mut new_handle = 0 as RawHandle;
|
|
let cur_proc = GetCurrentProcess();
|
|
if DuplicateHandle(
|
|
cur_proc,
|
|
old_handle,
|
|
cur_proc,
|
|
&mut new_handle,
|
|
0, // dwDesiredAccess; this flag is ignored if DUPLICATE_SAME_ACCESS is specified
|
|
FALSE,
|
|
DUPLICATE_SAME_ACCESS,
|
|
) == FALSE
|
|
{
|
|
Err(winerror::WinError::last())
|
|
} else {
|
|
Ok(new_handle)
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn close(handle: RawHandle) -> Result<()> {
|
|
use winapi::um::handleapi::CloseHandle;
|
|
if unsafe { CloseHandle(handle) } == FALSE {
|
|
Err(winerror::WinError::last())
|
|
} else {
|
|
Ok(())
|
|
}
|
|
}
|