diff --git a/crates/storage/libmdbx-rs/src/environment.rs b/crates/storage/libmdbx-rs/src/environment.rs index 5dba20a19b..abb3457c0b 100644 --- a/crates/storage/libmdbx-rs/src/environment.rs +++ b/crates/storage/libmdbx-rs/src/environment.rs @@ -8,10 +8,6 @@ use crate::{ use byteorder::{ByteOrder, NativeEndian}; use libc::c_uint; use mem::size_of; -#[cfg(unix)] -use std::os::unix::ffi::OsStrExt; -#[cfg(windows)] -use std::os::windows::ffi::OsStrExt; use std::{ ffi::CString, fmt, @@ -457,9 +453,23 @@ where } } - let path = match CString::new(path.as_os_str().as_bytes()) { + #[cfg(unix)] + fn path_to_bytes>(path: P) -> Vec { + use std::os::unix::ffi::OsStrExt; + path.as_ref().as_os_str().as_bytes().to_vec() + } + + #[cfg(windows)] + fn path_to_bytes>(path: P) -> Vec { + // On Windows, could use std::os::windows::ffi::OsStrExt to encode_wide(), + // but we end up with a Vec instead of a Vec, so that doesn't + // really help. + path.as_ref().to_string_lossy().to_string().into_bytes() + } + + let path = match CString::new(path_to_bytes(path)) { Ok(path) => path, - Err(..) => return Err(crate::Error::Invalid), + Err(_) => return Err(Error::Invalid), }; mdbx_result(ffi::mdbx_env_open( env,