pub mod os {
#[cfg(unix)]
use std::ffi::CStr;
#[cfg(not(target_arch = "wasm32"))]
pub fn real_hostname() -> anyhow::Result<String> {
Ok(sys_info::hostname()?)
}
#[cfg(target_arch = "wasm32")]
pub fn real_hostname() -> anyhow::Result<String> {
anyhow::bail!("hostname not available on wasm")
}
pub const fn os_name() -> &'static str {
std::env::consts::OS
}
pub const fn architecture() -> &'static str {
std::env::consts::ARCH
}
#[cfg(not(target_arch = "wasm32"))]
pub fn os_version() -> anyhow::Result<String> {
sys_info::os_release().map_err(|e| e.into())
}
#[cfg(target_arch = "wasm32")]
pub fn os_version() -> anyhow::Result<String> {
anyhow::bail!("os_version not available on wasm")
}
#[cfg(not(target_arch = "wasm32"))]
pub fn os_type() -> Option<String> {
sys_info::os_type().ok()
}
#[cfg(target_arch = "wasm32")]
pub fn os_type() -> Option<String> {
None
}
#[cfg(not(target_arch = "wasm32"))]
pub fn os_release() -> Option<String> {
sys_info::os_release().ok()
}
#[cfg(target_arch = "wasm32")]
pub fn os_release() -> Option<String> {
None
}
#[cfg(unix)]
pub unsafe fn uname() -> Option<String> {
let mut n = std::mem::zeroed();
match libc::uname(&mut n) {
0 => Some(
CStr::from_ptr(n.version.as_ptr())
.to_string_lossy()
.into_owned(),
),
_ => None,
}
}
}