-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move back to the main nightly channel #723
Closed
alexcrichton
wants to merge
3
commits into
bytecodealliance:master
from
alexcrichton:back-to-nightly
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Don't use
libc
in wasi-tests
We don't know what version of the wasi api it's compiled against, so let's avoid it.
- Loading branch information
commit 226a8af09069fea3e9d716fd5a06b41f0cb4d5fe
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
pub mod utils; | ||
pub mod wasi_wrappers; | ||
|
||
use libc; | ||
use std::ffi::CString; | ||
use std::io; | ||
use wasi_old::wasi_unstable; | ||
|
||
/// Opens a fresh file descriptor for `path` where `path` should be a preopened | ||
/// directory. This is intended to be used with `wasi_unstable`, not with | ||
/// `wasi_snapshot_preview1`. This is getting phased out and will likely be | ||
/// deleted soon. | ||
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; | ||
unsafe { | ||
for i in 3.. { | ||
let stat = match wasi_unstable::fd_prestat_get(i) { | ||
Ok(s) => s, | ||
Err(_) => break, | ||
}; | ||
if stat.pr_type != wasi::PREOPENTYPE_DIR { | ||
continue; | ||
} | ||
let mut dst = Vec::with_capacity(stat.u.dir.pr_name_len); | ||
if wasi::fd_prestat_dir_name(i, dst.as_mut_ptr(), dst.capacity()).is_err() { | ||
continue; | ||
} | ||
dst.set_len(stat.u.dir.pr_name_len); | ||
if dst == path.as_bytes() { | ||
return Ok(wasi::path_open(i, 0, ".", wasi::OFLAGS_DIRECTORY, 0, 0, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, and here as well, we call |
||
.expect("failed to open dir")); | ||
} | ||
} | ||
|
||
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) | ||
Err(format!("failed to find scratch dir")) | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, is it OK to mix
wasi_unstable
andwasi
for the syscalls here? I mean, first, we callwasi_unstable::fd_prestat_get
just to later on callwasi::fd_prestat_dir_name
. It might be OK, but definitely looks confusing!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops this was a mistake! I'll switch this as well to match the above