#[cfg(not(windows))]
pub fn system(command: &str) -> i32 {
extern "C" {
pub fn system(s: *const std::ffi::c_char) -> std::ffi::c_int;
}
let c_command = match std::ffi::CString::new(command) {
Ok(s) => s,
Err(_) => return -1,
};
unsafe { system(c_command.as_ptr()) }
}
#[cfg(windows)]
pub fn system(command: &str) -> i32 {
use std::os::windows::ffi::OsStrExt;
extern "C" {
pub fn _wsystem(command: *const std::ffi::c_ushort) -> std::ffi::c_int;
}
if command.find("\0").is_some() {
return -1;
}
let wide: Vec<u16> = std::ffi::OsStr::new(command)
.encode_wide()
.chain(std::iter::once(0))
.collect();
unsafe { _wsystem(wide.as_ptr()) }
}