about summary refs log tree commit diff
path: root/src/libstd/sys/unix/net.rs
diff options
context:
space:
mode:
authorBryan Drewery <bryan@shatow.net>2018-03-02 12:50:07 -0800
committerBryan Drewery <bryan@shatow.net>2018-03-02 12:54:03 -0800
commit5ba6b3a728fb50cd65237b8eeac2f2df05c3c77f (patch)
tree93a97596ff49b48b7a0d75f1c3c1d2cea66fe27a /src/libstd/sys/unix/net.rs
parent99b50efb6eb048297cda699ad017821822591d7a (diff)
downloadrust-5ba6b3a728fb50cd65237b8eeac2f2df05c3c77f.tar.gz
rust-5ba6b3a728fb50cd65237b8eeac2f2df05c3c77f.zip
Move glibc version lookup handling to sys::os and add a simpler glibc_version()
Diffstat (limited to 'src/libstd/sys/unix/net.rs')
-rw-r--r--src/libstd/sys/unix/net.rs33
1 files changed, 5 insertions, 28 deletions
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index 3f65975e608..04d9f0b06d3 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -383,12 +383,12 @@ impl IntoInner<c_int> for Socket {
 // 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::*;