]> git.lizzy.rs Git - rust.git/commitdiff
Move glibc version lookup handling to sys::os and add a simpler glibc_version()
authorBryan Drewery <bryan@shatow.net>
Fri, 2 Mar 2018 20:50:07 +0000 (12:50 -0800)
committerBryan Drewery <bryan@shatow.net>
Fri, 2 Mar 2018 20:54:03 +0000 (12:54 -0800)
src/libstd/sys/unix/net.rs
src/libstd/sys/unix/os.rs

index 3f65975e608800a7198d6c36bb84832e4a437a62..04d9f0b06d344efbda8cce7bebdcd6bdd835c983 100644 (file)
@@ -383,12 +383,12 @@ fn into_inner(self) -> c_int { self.0.into_raw() }
 // believe it's thread-safe).
 #[cfg(target_env = "gnu")]
 fn on_resolver_failure() {
+    use sys;
+
     // If the version fails to parse, we treat it the same as "not glibc".
-    if let Some(Ok(version_str)) = glibc_version_cstr().map(CStr::to_str) {
-        if let Some(version) = parse_glibc_version(version_str) {
-            if version < (2, 26) {
-                unsafe { libc::res_init() };
-            }
+    if let Some(version) = sys::os::glibc_version() {
+        if version < (2, 26) {
+            unsafe { libc::res_init() };
         }
     }
 }
@@ -396,29 +396,6 @@ fn on_resolver_failure() {
 #[cfg(not(target_env = "gnu"))]
 fn on_resolver_failure() {}
 
-#[cfg(target_env = "gnu")]
-fn glibc_version_cstr() -> Option<&'static CStr> {
-    weak! {
-        fn gnu_get_libc_version() -> *const libc::c_char
-    }
-    if let Some(f) = gnu_get_libc_version.get() {
-        unsafe { Some(CStr::from_ptr(f())) }
-    } else {
-        None
-    }
-}
-
-// Returns Some((major, minor)) if the string is a valid "x.y" version,
-// ignoring any extra dot-separated parts. Otherwise return None.
-#[cfg(target_env = "gnu")]
-fn parse_glibc_version(version: &str) -> Option<(usize, usize)> {
-    let mut parsed_ints = version.split(".").map(str::parse::<usize>).fuse();
-    match (parsed_ints.next(), parsed_ints.next()) {
-        (Some(Ok(major)), Some(Ok(minor))) => Some((major, minor)),
-        _ => None
-    }
-}
-
 #[cfg(all(test, taget_env = "gnu"))]
 mod test {
     use super::*;
index a46e855b4a6f4ed4febec988f3753e6712e9c44a..4c86fddee4b45c3eef51466095edc283340e9839 100644 (file)
@@ -546,3 +546,35 @@ pub fn getpid() -> u32 {
 pub fn getppid() -> u32 {
     unsafe { libc::getppid() as u32 }
 }
+
+#[cfg(target_env = "gnu")]
+pub fn glibc_version() -> Option<(usize, usize)> {
+    if let Some(Ok(version_str)) = glibc_version_cstr().map(CStr::to_str) {
+        parse_glibc_version(version_str)
+    } else {
+        None
+    }
+}
+
+#[cfg(target_env = "gnu")]
+fn glibc_version_cstr() -> Option<&'static CStr> {
+    weak! {
+        fn gnu_get_libc_version() -> *const libc::c_char
+    }
+    if let Some(f) = gnu_get_libc_version.get() {
+        unsafe { Some(CStr::from_ptr(f())) }
+    } else {
+        None
+    }
+}
+
+// Returns Some((major, minor)) if the string is a valid "x.y" version,
+// ignoring any extra dot-separated parts. Otherwise return None.
+#[cfg(target_env = "gnu")]
+fn parse_glibc_version(version: &str) -> Option<(usize, usize)> {
+    let mut parsed_ints = version.split(".").map(str::parse::<usize>).fuse();
+    match (parsed_ints.next(), parsed_ints.next()) {
+        (Some(Ok(major)), Some(Ok(minor))) => Some((major, minor)),
+        _ => None
+    }
+}