diff options
Diffstat (limited to 'src/librustc_llvm/archive_ro.rs')
| -rw-r--r-- | src/librustc_llvm/archive_ro.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/librustc_llvm/archive_ro.rs b/src/librustc_llvm/archive_ro.rs index 14a99026aac..f54480e3e52 100644 --- a/src/librustc_llvm/archive_ro.rs +++ b/src/librustc_llvm/archive_ro.rs @@ -16,6 +16,7 @@ use ArchiveRef; use std::ffi::CString; use std::mem; use std::raw; +use std::path::Path; pub struct ArchiveRO { ptr: ArchiveRef, @@ -29,14 +30,25 @@ impl ArchiveRO { /// If this archive is used with a mutable method, then an error will be /// raised. pub fn open(dst: &Path) -> Option<ArchiveRO> { - unsafe { - let s = CString::new(dst.as_vec()).unwrap(); + return unsafe { + let s = path2cstr(dst); let ar = ::LLVMRustOpenArchive(s.as_ptr()); if ar.is_null() { None } else { Some(ArchiveRO { ptr: ar }) } + }; + + #[cfg(unix)] + fn path2cstr(p: &Path) -> CString { + use std::os::unix::prelude::*; + use std::ffi::AsOsStr; + CString::new(p.as_os_str().as_bytes()).unwrap() + } + #[cfg(windows)] + fn path2cstr(p: &Path) -> CString { + CString::new(p.to_str().unwrap()).unwrap() } } |
