From a3975a321acb29e6401e6f73f047ea38cb014ea5 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 26 Sep 2024 21:43:35 +0200 Subject: [PATCH] Better path_to_c_string impl --- compiler/rustc_fs_util/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_fs_util/src/lib.rs b/compiler/rustc_fs_util/src/lib.rs index b7f267b4bbd11..21ef09e256420 100644 --- a/compiler/rustc_fs_util/src/lib.rs +++ b/compiler/rustc_fs_util/src/lib.rs @@ -1,4 +1,3 @@ -#[cfg(any(unix, windows, target_os = "wasi"))] use std::ffi::CString; use std::path::{absolute, Path, PathBuf}; use std::{fs, io}; @@ -77,14 +76,18 @@ pub fn link_or_copy, Q: AsRef>(p: P, q: Q) -> io::Result
  • CString { use std::ffi::OsStr; + #[cfg(unix)] use std::os::unix::ffi::OsStrExt; + #[cfg(all(target_os = "wasi", target_env = "p1"))] + use std::os::wasi::ffi::OsStrExt; + let p: &OsStr = p.as_ref(); CString::new(p.as_bytes()).unwrap() } -#[cfg(any(windows, target_os = "wasi"))] +#[cfg(windows)] pub fn path_to_c_string(p: &Path) -> CString { CString::new(p.to_str().unwrap()).unwrap() }