diff options
Diffstat (limited to 'src/features.rs')
-rw-r--r-- | src/features.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/features.rs b/src/features.rs index ed80fd71..61080986 100644 --- a/src/features.rs +++ b/src/features.rs @@ -3,7 +3,9 @@ pub use self::os::*; #[cfg(any(target_os = "linux", target_os = "android"))] mod os { + use std::os::unix::ffi::OsStrExt; use crate::sys::utsname::uname; + use crate::Result; // Features: // * atomic cloexec on socket: 2.6.27 @@ -22,15 +24,15 @@ mod os { *dst += (b - b'0') as usize; } - fn parse_kernel_version() -> usize { - let u = uname(); + fn parse_kernel_version() -> Result<usize> { + let u = uname()?; let mut curr: usize = 0; let mut major: usize = 0; let mut minor: usize = 0; let mut patch: usize = 0; - for b in u.release().bytes() { + for &b in u.release().as_bytes() { if curr >= 3 { break; } @@ -50,7 +52,7 @@ mod os { } } - if major >= 3 { + Ok(if major >= 3 { VERS_3 } else if major >= 2 { if minor >= 7 { @@ -68,29 +70,29 @@ mod os { } } else { VERS_UNKNOWN - } + }) } - fn kernel_version() -> usize { + fn kernel_version() -> Result<usize> { static mut KERNEL_VERS: usize = 0; unsafe { if KERNEL_VERS == 0 { - KERNEL_VERS = parse_kernel_version(); + KERNEL_VERS = parse_kernel_version()?; } - KERNEL_VERS + Ok(KERNEL_VERS) } } /// Check if the OS supports atomic close-on-exec for sockets pub fn socket_atomic_cloexec() -> bool { - kernel_version() >= VERS_2_6_27 + kernel_version().map(|version| version >= VERS_2_6_27).unwrap_or(false) } #[test] pub fn test_parsing_kernel_version() { - assert!(kernel_version() > 0); + assert!(kernel_version().unwrap() > 0); } } |