Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ WhoAmI targets all platforms that can run Rust, including:
- Android **planned later**
- iOS / watchOS / tvOS **planned later**
- Fuchsia **planned later**
- GNU/Hurd **untested**
- Others? (make a PR or open an issue)

## MSRV
Expand Down
1 change: 1 addition & 0 deletions src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
target_os = "netbsd",
target_os = "openbsd",
target_os = "illumos",
target_os = "hurd",
),
not(target_arch = "wasm32")
),
Expand Down
2 changes: 1 addition & 1 deletion src/os/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Target for Os {
} else if cfg!(target_os = "vita") {
Platform::PlayStation
} else if cfg!(target_os = "hurd") {
Platform::Unknown("GNU Hurd".to_string())
Platform::Hurd
} else if cfg!(target_os = "aix") {
Platform::Unknown("AIX OS".to_string())
} else if cfg!(target_os = "espidf") {
Expand Down
25 changes: 24 additions & 1 deletion src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::convert::TryInto;
target_os = "netbsd",
target_os = "openbsd",
target_os = "illumos",
target_os = "hurd",
))]
use std::env;
use std::{
Expand Down Expand Up @@ -34,7 +35,7 @@ use crate::{
Arch, DesktopEnv, Platform, Result,
};

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "hurd",))]
#[repr(C)]
struct PassWd {
pw_name: *const c_void,
Expand Down Expand Up @@ -99,6 +100,7 @@ extern "system" {
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "hurd",
))]
extern "system" {
fn getpwuid_r(
Expand Down Expand Up @@ -250,6 +252,7 @@ fn getpwuid(name: Name) -> Result<OsString> {
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "hurd",
))]
{
let mut _passwd = mem::MaybeUninit::<*mut PassWd>::uninit();
Expand Down Expand Up @@ -403,6 +406,16 @@ struct UtsName {
domainname: [c_char; 65],
}

#[cfg(target_os = "hurd")]
#[repr(C)]
struct UtsName {
sysname: [c_char; 1024],
nodename: [c_char; 1024],
release: [c_char; 1024],
version: [c_char; 1024],
machine: [c_char; 1024],
}

// Buffer initialization
impl Default for UtsName {
fn default() -> Self {
Expand All @@ -420,6 +433,7 @@ unsafe fn uname(buf: *mut UtsName) -> c_int {
target_os = "netbsd",
target_os = "openbsd",
target_os = "illumos",
target_os = "hurd",
))]
fn uname(buf: *mut UtsName) -> c_int;

Expand Down Expand Up @@ -486,6 +500,7 @@ impl Target for Os {
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "hurd",
))]
{
let machine_info = fs::read("/etc/machine-info")?;
Expand Down Expand Up @@ -545,6 +560,7 @@ impl Target for Os {
target_os = "netbsd",
target_os = "openbsd",
target_os = "illumos",
target_os = "hurd",
))]
{
let program = fs::read("/etc/os-release")?;
Expand Down Expand Up @@ -591,6 +607,7 @@ impl Target for Os {
target_os = "netbsd",
target_os = "openbsd",
target_os = "illumos",
target_os = "hurd",
))]
let env = env::var_os("DESKTOP_SESSION");
#[cfg(any(
Expand All @@ -600,6 +617,7 @@ impl Target for Os {
target_os = "netbsd",
target_os = "openbsd",
target_os = "illumos",
target_os = "hurd",
))]
let env = if let Some(ref env) = env {
env.to_string_lossy()
Expand Down Expand Up @@ -653,6 +671,11 @@ impl Target for Os {
{
Platform::Illumos
}

#[cfg(target_os = "hurd")]
{
Platform::Hurd
}
}

#[inline(always)]
Expand Down
2 changes: 2 additions & 0 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum Platform {
PlayStation,
Fuchsia,
Redox,
Hurd,
Unknown(String),
}

Expand All @@ -44,6 +45,7 @@ impl Display for Platform {
Self::PlayStation => "PlayStation",
Self::Fuchsia => "Fuchsia",
Self::Redox => "Redox",
Self::Hurd => "GNU Hurd",
Self::Unknown(a) => a,
})
}
Expand Down
Loading