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>
This commit is contained in:
Jiwoo Ahn authored and GitHub committed 2026-08-09 15:09:18 +09:00
1 parent 3a1caa1eb5
commit 689c8b57e7
1 file changed
+4 -3
+4 -3
View File
@@ -519,13 +519,14 @@ pub fn set_errno(value: i32) {
#[cfg(not(any(unix, windows, target_os = "wasi")))]
pub fn set_errno(_value: i32) {}
#[cfg(unix)]
// WASIp1, like Unix, provides byte-preserving OsStr conversions.
#[cfg(any(unix, all(target_os = "wasi", not(target_env = "p2"))))]
pub fn bytes_as_os_str(b: &[u8]) -> Result<&std::ffi::OsStr, Utf8Error> {
use std::os::unix::ffi::OsStrExt;
use self::ffi::OsStrExt;
Ok(std::ffi::OsStr::from_bytes(b))
}
#[cfg(not(unix))]
#[cfg(not(any(unix, all(target_os = "wasi", not(target_env = "p2")))))]
pub fn bytes_as_os_str(b: &[u8]) -> Result<&std::ffi::OsStr, Utf8Error> {
Ok(core::str::from_utf8(b)?.as_ref())
}