tiny_std/unix/host_name.rs
1/// Attempts to get the system hostname as a utf8 `String`
2/// # Errors
3/// Hostname is not utf8
4#[cfg(feature = "alloc")]
5pub fn host_name() -> Result<alloc::string::String, crate::error::Error> {
6 #[allow(unused_imports)]
7 use alloc::string::ToString;
8 let raw = rusl::unistd::uname()?;
9 Ok(raw.nodename()?.to_string())
10}
11
12#[cfg(test)]
13mod tests {
14 #[test]
15 #[cfg(feature = "alloc")]
16 fn get_host_name() {
17 let host = crate::unix::host_name::host_name().unwrap();
18 assert!(!host.is_empty());
19 }
20}