system_info/unix/
mod.rs

1mod posix;
2#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "macos", target_os = "ios")))]
3pub use posix::*;
4
5#[cfg(any(target_os = "macos", target_os = "ios"))]
6mod apple;
7#[cfg(any(target_os = "macos", target_os = "ios"))]
8pub use apple::*;
9
10#[cfg(any(target_os = "linux", target_os = "android"))]
11mod linux;
12#[cfg(any(target_os = "linux", target_os = "android"))]
13pub use linux::*;
14
15pub use crate::data::host::HostName;
16
17impl HostName {
18    ///Retrieves host's name.
19    pub fn get() -> Option<HostName> {
20        let mut name = [0u8; HostName::capacity()];
21        let res = unsafe {
22            libc::gethostname(name.as_mut_ptr() as _, name.len())
23        };
24
25        if res == 0 {
26            Some(HostName::name(name))
27        } else {
28            None
29        }
30    }
31}