Skip to content

Commit 689c8b5

Browse files
authored
wasi: fix os.environb byte handling (#8476)
Part of: #4583 This will enable -m test for wasi preview 1 Signed-off-by: Jiwoo Ahn <ikwydls1314@gmail.com>
1 parent 3a1caa1 commit 689c8b5

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

crates/host_env/src/os.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,14 @@ pub fn set_errno(value: i32) {
519519
#[cfg(not(any(unix, windows, target_os = "wasi")))]
520520
pub fn set_errno(_value: i32) {}
521521

522-
#[cfg(unix)]
522+
// WASIp1, like Unix, provides byte-preserving OsStr conversions.
523+
#[cfg(any(unix, all(target_os = "wasi", not(target_env = "p2"))))]
523524
pub fn bytes_as_os_str(b: &[u8]) -> Result<&std::ffi::OsStr, Utf8Error> {
524-
use std::os::unix::ffi::OsStrExt;
525+
use self::ffi::OsStrExt;
525526
Ok(std::ffi::OsStr::from_bytes(b))
526527
}
527528

528-
#[cfg(not(unix))]
529+
#[cfg(not(any(unix, all(target_os = "wasi", not(target_env = "p2")))))]
529530
pub fn bytes_as_os_str(b: &[u8]) -> Result<&std::ffi::OsStr, Utf8Error> {
530531
Ok(core::str::from_utf8(b)?.as_ref())
531532
}

0 commit comments

Comments
 (0)