Initial reorg.
This is largely the same as #305, but updated for the current tree.
This commit is contained in:
25
crates/wasi-common/wasi-misc-tests/src/lib.rs
Normal file
25
crates/wasi-common/wasi-misc-tests/src/lib.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
pub mod utils;
|
||||
pub mod wasi_wrappers;
|
||||
|
||||
use libc;
|
||||
use std::ffi::CString;
|
||||
use std::io;
|
||||
use wasi::wasi_unstable;
|
||||
|
||||
pub fn open_scratch_directory(path: &str) -> Result<wasi_unstable::Fd, String> {
|
||||
// Open the scratch directory.
|
||||
let dir_fd: wasi_unstable::Fd = unsafe {
|
||||
let cstr = CString::new(path.as_bytes()).unwrap();
|
||||
libc::open(cstr.as_ptr(), libc::O_RDONLY | libc::O_DIRECTORY)
|
||||
} as wasi_unstable::Fd;
|
||||
|
||||
if (dir_fd as std::os::raw::c_int) < 0 {
|
||||
Err(format!(
|
||||
"error opening scratch directory '{}': {}",
|
||||
path,
|
||||
io::Error::last_os_error()
|
||||
))
|
||||
} else {
|
||||
Ok(dir_fd)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user