about summary refs log tree commit diff
path: root/src/libstd/sys/unix
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/sys/unix')
-rw-r--r--src/libstd/sys/unix/c.rs452
-rw-r--r--src/libstd/sys/unix/condvar.rs21
-rw-r--r--src/libstd/sys/unix/fd.rs7
-rw-r--r--src/libstd/sys/unix/fs.rs18
-rw-r--r--src/libstd/sys/unix/mod.rs6
-rw-r--r--src/libstd/sys/unix/mutex.rs42
-rw-r--r--src/libstd/sys/unix/net.rs59
-rw-r--r--src/libstd/sys/unix/os.rs22
-rw-r--r--src/libstd/sys/unix/process.rs45
-rw-r--r--src/libstd/sys/unix/rwlock.rs19
-rw-r--r--src/libstd/sys/unix/stack_overflow.rs30
-rw-r--r--src/libstd/sys/unix/sync.rs374
-rw-r--r--src/libstd/sys/unix/thread.rs143
-rw-r--r--src/libstd/sys/unix/thread_local.rs45
-rw-r--r--src/libstd/sys/unix/time.rs17
15 files changed, 203 insertions, 1097 deletions
diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs
deleted file mode 100644
index fc6af6447d2..00000000000
--- a/src/libstd/sys/unix/c.rs
+++ /dev/null
@@ -1,452 +0,0 @@
-// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! C definitions used by std::sys that don't belong in liblibc
-
-// These are definitions sufficient for the users in this directory.
-// This is not a general-purpose binding to this functionality, and in
-// some cases (notably the definition of siginfo_t), we intentionally
-// have incomplete bindings so that we don't need to fight with unions.
-//
-// Note that these types need to match the definitions from the platform
-// libc (currently glibc on Linux), not the kernel definitions / the
-// syscall interface.  This has a few weirdnesses, like glibc's sigset_t
-// being 1024 bits on all platforms. If you're adding a new GNU/Linux
-// port, check glibc's sysdeps/unix/sysv/linux, not the kernel headers.
-
-#![allow(dead_code)]
-#![allow(non_camel_case_types)]
-
-pub use self::signal_os::*;
-use libc;
-
-#[cfg(any(target_os = "macos",
-          target_os = "ios",
-          target_os = "freebsd",
-          target_os = "dragonfly",
-          target_os = "bitrig",
-          target_os = "netbsd",
-          target_os = "openbsd"))]
-pub const FIOCLEX: libc::c_ulong = 0x20006601;
-
-#[cfg(any(all(target_os = "linux",
-              any(target_arch = "x86",
-                  target_arch = "x86_64",
-                  target_arch = "arm",
-                  target_arch = "aarch64")),
-          target_os = "android"))]
-pub const FIOCLEX: libc::c_ulong = 0x5451;
-
-#[cfg(all(target_os = "linux",
-          any(target_arch = "mips",
-              target_arch = "mipsel",
-              target_arch = "powerpc")))]
-pub const FIOCLEX: libc::c_ulong = 0x6601;
-
-#[cfg(target_env = "newlib")]
-pub const FD_CLOEXEC: libc::c_int = 1;
-#[cfg(target_env = "newlib")]
-pub const F_GETFD: libc::c_int = 1;
-#[cfg(target_env = "newlib")]
-pub const F_SETFD: libc::c_int = 2;
-
-pub const WNOHANG: libc::c_int = 1;
-
-#[cfg(target_os = "linux")]
-pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70;
-#[cfg(any(target_os = "macos",
-          target_os = "freebsd",
-          target_os = "dragonfly"))]
-pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71;
-#[cfg(any(target_os = "bitrig",
-          target_os = "openbsd"))]
-pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101;
-#[cfg(target_os = "netbsd")]
-pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 48;
-#[cfg(target_os = "android")]
-pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048;
-
-#[repr(C)]
-#[cfg(target_os = "linux")]
-pub struct passwd {
-    pub pw_name: *mut libc::c_char,
-    pub pw_passwd: *mut libc::c_char,
-    pub pw_uid: libc::uid_t,
-    pub pw_gid: libc::gid_t,
-    pub pw_gecos: *mut libc::c_char,
-    pub pw_dir: *mut libc::c_char,
-    pub pw_shell: *mut libc::c_char,
-}
-#[repr(C)]
-#[cfg(target_env = "newlib")]
-pub struct passwd {
-    pub pw_name: *mut libc::c_char,
-    pub pw_passwd: *mut libc::c_char,
-    pub pw_uid: libc::uid_t,
-    pub pw_gid: libc::gid_t,
-    pub pw_comment: *mut libc::c_char,
-    pub pw_gecos: *mut libc::c_char,
-    pub pw_dir: *mut libc::c_char,
-    pub pw_shell: *mut libc::c_char,
-}
-
-#[repr(C)]
-#[cfg(any(target_os = "macos",
-          target_os = "freebsd",
-          target_os = "dragonfly",
-          target_os = "bitrig",
-          target_os = "netbsd",
-          target_os = "openbsd"))]
-pub struct passwd {
-    pub pw_name: *mut libc::c_char,
-    pub pw_passwd: *mut libc::c_char,
-    pub pw_uid: libc::uid_t,
-    pub pw_gid: libc::gid_t,
-    pub pw_change: libc::time_t,
-    pub pw_class: *mut libc::c_char,
-    pub pw_gecos: *mut libc::c_char,
-    pub pw_dir: *mut libc::c_char,
-    pub pw_shell: *mut libc::c_char,
-    pub pw_expire: libc::time_t,
-}
-
-#[repr(C)]
-#[cfg(target_os = "android")]
-pub struct passwd {
-    pub pw_name: *mut libc::c_char,
-    pub pw_passwd: *mut libc::c_char,
-    pub pw_uid: libc::uid_t,
-    pub pw_gid: libc::gid_t,
-    pub pw_dir: *mut libc::c_char,
-    pub pw_shell: *mut libc::c_char,
-}
-
-// This is really a function pointer (or a union of multiple function
-// pointers), except for constants like SIG_DFL.
-pub type sighandler_t = *mut libc::c_void;
-
-pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
-pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
-
-extern {
-    pub fn getsockopt(sockfd: libc::c_int,
-                      level: libc::c_int,
-                      optname: libc::c_int,
-                      optval: *mut libc::c_void,
-                      optlen: *mut libc::socklen_t) -> libc::c_int;
-    #[cfg(not(target_env = "newlib"))]
-    pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
-    #[cfg(target_env = "newlib")]
-    pub fn fnctl(fd: libc::c_int, req: libc::c_int, ...) -> libc::c_int;
-
-
-    pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
-                   options: libc::c_int) -> libc::pid_t;
-
-    pub fn raise(signum: libc::c_int) -> libc::c_int;
-
-    #[cfg_attr(target_os = "netbsd", link_name = "__sigaction14")]
-    pub fn sigaction(signum: libc::c_int,
-                     act: *const sigaction,
-                     oldact: *mut sigaction) -> libc::c_int;
-
-    #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
-    #[cfg(not(target_env = "newlib"))]
-    pub fn sigaltstack(ss: *const sigaltstack,
-                       oss: *mut sigaltstack) -> libc::c_int;
-
-    #[cfg(not(target_os = "android"))]
-    #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
-    pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
-
-    pub fn pthread_sigmask(how: libc::c_int, set: *const sigset_t,
-                           oldset: *mut sigset_t) -> libc::c_int;
-
-    #[cfg(not(target_os = "ios"))]
-    #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
-    pub fn getpwuid_r(uid: libc::uid_t,
-                      pwd: *mut passwd,
-                      buf: *mut libc::c_char,
-                      buflen: libc::size_t,
-                      result: *mut *mut passwd) -> libc::c_int;
-
-    #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")]
-    pub fn utimes(filename: *const libc::c_char,
-                  times: *const libc::timeval) -> libc::c_int;
-    pub fn gai_strerror(errcode: libc::c_int) -> *const libc::c_char;
-    /// Newlib has this, but only for Cygwin.
-    #[cfg(not(target_os = "nacl"))]
-    pub fn setgroups(ngroups: libc::c_int,
-                     ptr: *const libc::c_void) -> libc::c_int;
-    pub fn realpath(pathname: *const libc::c_char, resolved: *mut libc::c_char)
-                    -> *mut libc::c_char;
-}
-
-// Ugh. This is only available as an inline until Android API 21.
-#[cfg(target_os = "android")]
-pub unsafe fn sigemptyset(set: *mut sigset_t) -> libc::c_int {
-    use intrinsics;
-    intrinsics::write_bytes(set, 0, 1);
-    return 0;
-}
-
-#[cfg(any(target_os = "linux",
-          target_os = "android"))]
-mod signal_os {
-    pub use self::arch::{SA_ONSTACK, SA_SIGINFO, SIGBUS, SIG_SETMASK,
-                         sigaction, sigaltstack};
-    use libc;
-
-    #[cfg(any(target_arch = "x86",
-              target_arch = "x86_64",
-              target_arch = "arm",
-              target_arch = "mips",
-              target_arch = "mipsel"))]
-    pub const SIGSTKSZ: libc::size_t = 8192;
-
-    // This is smaller on musl and Android, but no harm in being generous.
-    #[cfg(any(target_arch = "aarch64",
-              target_arch = "powerpc"))]
-    pub const SIGSTKSZ: libc::size_t = 16384;
-
-    // This definition is intentionally a subset of the C structure: the
-    // fields after si_code are actually a giant union. We're only
-    // interested in si_addr for this module, though.
-    #[repr(C)]
-    pub struct siginfo {
-        _signo: libc::c_int,
-        _errno: libc::c_int,
-        _code: libc::c_int,
-        // This structure will need extra padding here for MIPS64.
-        pub si_addr: *mut libc::c_void
-    }
-
-    #[cfg(all(target_os = "linux", target_pointer_width = "32"))]
-    #[repr(C)]
-    pub struct sigset_t {
-        __val: [libc::c_ulong; 32],
-    }
-
-    #[cfg(all(target_os = "linux", target_pointer_width = "64"))]
-    #[repr(C)]
-    pub struct sigset_t {
-        __val: [libc::c_ulong; 16],
-    }
-
-    // Android for MIPS has a 128-bit sigset_t, but we don't currently
-    // support it. Android for AArch64 technically has a structure of a
-    // single ulong.
-    #[cfg(target_os = "android")]
-    pub type sigset_t = libc::c_ulong;
-
-    #[cfg(any(target_arch = "x86",
-              target_arch = "x86_64",
-              target_arch = "powerpc",
-              target_arch = "arm",
-              target_arch = "aarch64"))]
-    mod arch {
-        use libc;
-        use super::super::sighandler_t;
-        use super::sigset_t;
-
-        pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
-        pub const SA_SIGINFO: libc::c_ulong = 0x00000004;
-
-        pub const SIGBUS: libc::c_int = 7;
-
-        pub const SIG_SETMASK: libc::c_int = 2;
-
-        #[cfg(target_os = "linux")]
-        #[repr(C)]
-        pub struct sigaction {
-            pub sa_sigaction: sighandler_t,
-            pub sa_mask: sigset_t,
-            pub sa_flags: libc::c_ulong,
-            _restorer: *mut libc::c_void,
-        }
-
-        #[cfg(all(target_os = "android", target_pointer_width = "32"))]
-        #[repr(C)]
-        pub struct sigaction {
-            pub sa_sigaction: sighandler_t,
-            pub sa_flags: libc::c_ulong,
-            _restorer: *mut libc::c_void,
-            pub sa_mask: sigset_t,
-        }
-
-        #[cfg(all(target_os = "android", target_pointer_width = "64"))]
-        #[repr(C)]
-        pub struct sigaction {
-            pub sa_flags: libc::c_uint,
-            pub sa_sigaction: sighandler_t,
-            pub sa_mask: sigset_t,
-            _restorer: *mut libc::c_void,
-        }
-
-        #[repr(C)]
-        pub struct sigaltstack {
-            pub ss_sp: *mut libc::c_void,
-            pub ss_flags: libc::c_int,
-            pub ss_size: libc::size_t
-        }
-    }
-
-    #[cfg(any(target_arch = "mips",
-              target_arch = "mipsel"))]
-    mod arch {
-        use libc;
-        use super::super::sighandler_t;
-        use super::sigset_t;
-
-        pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
-        pub const SA_SIGINFO: libc::c_ulong = 0x00000008;
-
-        pub const SIGBUS: libc::c_int = 10;
-
-        pub const SIG_SETMASK: libc::c_int = 3;
-
-        #[cfg(all(target_os = "linux", not(target_env = "musl")))]
-        #[repr(C)]
-        pub struct sigaction {
-            pub sa_flags: libc::c_uint,
-            pub sa_sigaction: sighandler_t,
-            pub sa_mask: sigset_t,
-            _restorer: *mut libc::c_void,
-            _resv: [libc::c_int; 1],
-        }
-
-        #[cfg(target_env = "musl")]
-        #[repr(C)]
-        pub struct sigaction {
-            pub sa_sigaction: sighandler_t,
-            pub sa_mask: sigset_t,
-            pub sa_flags: libc::c_ulong,
-            _restorer: *mut libc::c_void,
-        }
-
-        #[cfg(target_os = "android")]
-        #[repr(C)]
-        pub struct sigaction {
-            pub sa_flags: libc::c_uint,
-            pub sa_sigaction: sighandler_t,
-            pub sa_mask: sigset_t,
-        }
-
-        #[repr(C)]
-        pub struct sigaltstack {
-            pub ss_sp: *mut libc::c_void,
-            pub ss_size: libc::size_t,
-            pub ss_flags: libc::c_int,
-        }
-    }
-}
-
-/// Note: Although the signal functions are defined on NaCl, they always fail.
-/// Also, this could be cfg-ed on newlib instead of nacl, but these structures
-/// can differ depending on the platform, so I've played it safe here.
-#[cfg(target_os = "nacl")]
-mod signal_os {
-    use libc;
-
-    pub static SA_NOCLDSTOP: libc::c_ulong = 1;
-    pub static SA_SIGINFO:   libc::c_ulong = 2;
-
-    pub type sigset_t = libc::c_ulong;
-    #[repr(C)]
-    pub struct sigaction {
-        pub sa_flags: libc::c_int,
-        pub sa_mask:  sigset_t,
-        pub handler:  extern fn(libc::c_int),
-    }
-}
-
-#[cfg(any(target_os = "macos",
-          target_os = "ios",
-          target_os = "freebsd",
-          target_os = "dragonfly",
-          target_os = "bitrig",
-          target_os = "netbsd",
-          target_os = "openbsd"))]
-mod signal_os {
-    use libc;
-    use super::sighandler_t;
-
-    pub const SA_ONSTACK: libc::c_int = 0x0001;
-    pub const SA_SIGINFO: libc::c_int = 0x0040;
-
-    pub const SIGBUS: libc::c_int = 10;
-
-    #[cfg(any(target_os = "macos", target_os = "ios"))]
-    pub const SIGSTKSZ: libc::size_t = 131072;
-    // FreeBSD's is actually arch-dependent, but never more than 40960.
-    // No harm in being generous.
-    #[cfg(not(any(target_os = "macos", target_os = "ios")))]
-    pub const SIGSTKSZ: libc::size_t = 40960;
-
-    pub const SIG_SETMASK: libc::c_int = 3;
-
-    #[cfg(any(target_os = "macos",
-              target_os = "ios"))]
-    pub type sigset_t = u32;
-    #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))]
-    #[repr(C)]
-    pub struct sigset_t {
-        bits: [u32; 4],
-    }
-    #[cfg(any(target_os = "bitrig", target_os = "openbsd"))]
-    pub type sigset_t = libc::c_uint;
-
-    // This structure has more fields, but we're not all that interested in
-    // them.
-    #[cfg(any(target_os = "macos", target_os = "ios",
-              target_os = "freebsd", target_os = "dragonfly"))]
-    #[repr(C)]
-    pub struct siginfo {
-        pub _signo: libc::c_int,
-        pub _errno: libc::c_int,
-        pub _code: libc::c_int,
-        pub _pid: libc::pid_t,
-        pub _uid: libc::uid_t,
-        pub _status: libc::c_int,
-        pub si_addr: *mut libc::c_void
-    }
-    #[cfg(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))]
-    #[repr(C)]
-    pub struct siginfo {
-        pub si_signo: libc::c_int,
-        pub si_code: libc::c_int,
-        pub si_errno: libc::c_int,
-        pub si_addr: *mut libc::c_void
-    }
-
-    #[cfg(any(target_os = "macos", target_os = "ios",
-              target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))]
-    #[repr(C)]
-    pub struct sigaction {
-        pub sa_sigaction: sighandler_t,
-        pub sa_mask: sigset_t,
-        pub sa_flags: libc::c_int,
-    }
-
-    #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
-    #[repr(C)]
-    pub struct sigaction {
-        pub sa_sigaction: sighandler_t,
-        pub sa_flags: libc::c_int,
-        pub sa_mask: sigset_t,
-    }
-
-    #[repr(C)]
-    pub struct sigaltstack {
-        pub ss_sp: *mut libc::c_void,
-        pub ss_size: libc::size_t,
-        pub ss_flags: libc::c_int,
-    }
-}
diff --git a/src/libstd/sys/unix/condvar.rs b/src/libstd/sys/unix/condvar.rs
index b9538867b25..3e0f41933e6 100644
--- a/src/libstd/sys/unix/condvar.rs
+++ b/src/libstd/sys/unix/condvar.rs
@@ -13,10 +13,9 @@ use libc;
 use ptr;
 use sys::mutex::{self, Mutex};
 use sys::time;
-use sys::sync as ffi;
 use time::Duration;
 
-pub struct Condvar { inner: UnsafeCell<ffi::pthread_cond_t> }
+pub struct Condvar { inner: UnsafeCell<libc::pthread_cond_t> }
 
 unsafe impl Send for Condvar {}
 unsafe impl Sync for Condvar {}
@@ -25,24 +24,24 @@ impl Condvar {
     pub const fn new() -> Condvar {
         // Might be moved and address is changing it is better to avoid
         // initialization of potentially opaque OS data before it landed
-        Condvar { inner: UnsafeCell::new(ffi::PTHREAD_COND_INITIALIZER) }
+        Condvar { inner: UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER) }
     }
 
     #[inline]
     pub unsafe fn notify_one(&self) {
-        let r = ffi::pthread_cond_signal(self.inner.get());
+        let r = libc::pthread_cond_signal(self.inner.get());
         debug_assert_eq!(r, 0);
     }
 
     #[inline]
     pub unsafe fn notify_all(&self) {
-        let r = ffi::pthread_cond_broadcast(self.inner.get());
+        let r = libc::pthread_cond_broadcast(self.inner.get());
         debug_assert_eq!(r, 0);
     }
 
     #[inline]
     pub unsafe fn wait(&self, mutex: &Mutex) {
-        let r = ffi::pthread_cond_wait(self.inner.get(), mutex::raw(mutex));
+        let r = libc::pthread_cond_wait(self.inner.get(), mutex::raw(mutex));
         debug_assert_eq!(r, 0);
     }
 
@@ -55,7 +54,7 @@ impl Condvar {
         // report timeout based on stable time.
         let mut sys_now = libc::timeval { tv_sec: 0, tv_usec: 0 };
         let stable_now = time::SteadyTime::now();
-        let r = ffi::gettimeofday(&mut sys_now, ptr::null_mut());
+        let r = libc::gettimeofday(&mut sys_now, ptr::null_mut());
         debug_assert_eq!(r, 0);
 
         let nsec = dur.subsec_nanos() as libc::c_long +
@@ -76,7 +75,7 @@ impl Condvar {
         });
 
         // And wait!
-        let r = ffi::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex),
+        let r = libc::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex),
                                             &timeout);
         debug_assert!(r == libc::ETIMEDOUT || r == 0);
 
@@ -88,17 +87,17 @@ impl Condvar {
     #[inline]
     #[cfg(not(target_os = "dragonfly"))]
     pub unsafe fn destroy(&self) {
-        let r = ffi::pthread_cond_destroy(self.inner.get());
+        let r = libc::pthread_cond_destroy(self.inner.get());
         debug_assert_eq!(r, 0);
     }
 
     #[inline]
     #[cfg(target_os = "dragonfly")]
     pub unsafe fn destroy(&self) {
-        let r = ffi::pthread_cond_destroy(self.inner.get());
+        let r = libc::pthread_cond_destroy(self.inner.get());
         // On DragonFly pthread_cond_destroy() returns EINVAL if called on
         // a condvar that was just initialized with
-        // ffi::PTHREAD_COND_INITIALIZER. Once it is used or
+        // libc::PTHREAD_COND_INITIALIZER. Once it is used or
         // pthread_cond_init() is called, this behaviour no longer occurs.
         debug_assert!(r == 0 || r == libc::EINVAL);
     }
diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs
index e9f442a22cc..d42c15a97ac 100644
--- a/src/libstd/sys/unix/fd.rs
+++ b/src/libstd/sys/unix/fd.rs
@@ -11,7 +11,6 @@
 use io;
 use libc::{self, c_int, size_t, c_void};
 use mem;
-use sys::c;
 use sys::cvt;
 use sys_common::AsInner;
 
@@ -54,15 +53,15 @@ impl FileDesc {
     #[cfg(not(target_env = "newlib"))]
     pub fn set_cloexec(&self) {
         unsafe {
-            let ret = c::ioctl(self.fd, c::FIOCLEX);
+            let ret = libc::ioctl(self.fd, libc::FIOCLEX);
             debug_assert_eq!(ret, 0);
         }
     }
     #[cfg(target_env = "newlib")]
     pub fn set_cloexec(&self) {
         unsafe {
-            let previous = c::fnctl(self.fd, c::F_GETFD);
-            let ret = c::fnctl(self.fd, c::F_SETFD, previous | c::FD_CLOEXEC);
+            let previous = libc::fnctl(self.fd, libc::F_GETFD);
+            let ret = libc::fnctl(self.fd, libc::F_SETFD, previous | libc::FD_CLOEXEC);
             debug_assert_eq!(ret, 0);
         }
     }
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index c2145ac875a..018c9100288 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -21,7 +21,7 @@ use ptr;
 use sync::Arc;
 use sys::fd::FileDesc;
 use sys::platform::raw;
-use sys::{c, cvt, cvt_r};
+use sys::{cvt, cvt_r};
 use sys_common::{AsInner, FromInner};
 use vec::Vec;
 
@@ -43,7 +43,7 @@ unsafe impl Send for Dir {}
 unsafe impl Sync for Dir {}
 
 pub struct DirEntry {
-    buf: Vec<u8>, // actually *mut libc::dirent_t
+    buf: Vec<u8>, // actually *mut libc::dirent
     root: Arc<PathBuf>,
 }
 
@@ -133,7 +133,7 @@ impl Iterator for ReadDir {
         let mut buf: Vec<u8> = Vec::with_capacity(unsafe {
             rust_dirent_t_size() as usize
         });
-        let ptr = buf.as_mut_ptr() as *mut libc::dirent_t;
+        let ptr = buf.as_mut_ptr() as *mut libc::dirent;
 
         let mut entry_ptr = ptr::null_mut();
         loop {
@@ -179,7 +179,7 @@ impl DirEntry {
 
     pub fn file_type(&self) -> io::Result<FileType> {
         extern {
-            fn rust_dir_get_mode(ptr: *mut libc::dirent_t) -> c_int;
+            fn rust_dir_get_mode(ptr: *mut libc::dirent) -> c_int;
         }
         unsafe {
             match rust_dir_get_mode(self.dirent()) {
@@ -191,21 +191,21 @@ impl DirEntry {
 
     pub fn ino(&self) -> raw::ino_t {
         extern {
-            fn rust_dir_get_ino(ptr: *mut libc::dirent_t) -> raw::ino_t;
+            fn rust_dir_get_ino(ptr: *mut libc::dirent) -> raw::ino_t;
         }
         unsafe { rust_dir_get_ino(self.dirent()) }
     }
 
     fn name_bytes(&self) -> &[u8] {
         extern {
-            fn rust_list_dir_val(ptr: *mut libc::dirent_t) -> *const c_char;
+            fn rust_list_dir_val(ptr: *mut libc::dirent) -> *const c_char;
         }
         unsafe {
             CStr::from_ptr(rust_list_dir_val(self.dirent())).to_bytes()
         }
     }
 
-    fn dirent(&self) -> *mut libc::dirent_t {
+    fn dirent(&self) -> *mut libc::dirent {
         self.buf.as_ptr() as *mut _
     }
 }
@@ -267,7 +267,7 @@ impl File {
             (false, false) => libc::O_RDONLY,
         };
         let fd = try!(cvt_r(|| unsafe {
-            libc::open(path.as_ptr(), flags, opts.mode)
+            libc::open(path.as_ptr(), flags, opts.mode as c_int)
         }));
         let fd = FileDesc::new(fd);
         // Even though we open with the O_CLOEXEC flag, still set CLOEXEC here,
@@ -532,7 +532,7 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
     let path = try!(CString::new(p.as_os_str().as_bytes()));
     let buf;
     unsafe {
-        let r = c::realpath(path.as_ptr(), ptr::null_mut());
+        let r = libc::realpath(path.as_ptr(), ptr::null_mut());
         if r.is_null() {
             return Err(io::Error::last_os_error())
         }
diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs
index 26b6b17cbe4..68b0c3d6b0e 100644
--- a/src/libstd/sys/unix/mod.rs
+++ b/src/libstd/sys/unix/mod.rs
@@ -28,7 +28,6 @@ use ops::Neg;
 #[cfg(target_os = "openbsd")]   pub use os::openbsd as platform;
 
 pub mod backtrace;
-pub mod c;
 pub mod condvar;
 pub mod ext;
 pub mod fd;
@@ -41,7 +40,6 @@ pub mod pipe;
 pub mod process;
 pub mod rwlock;
 pub mod stack_overflow;
-pub mod sync;
 pub mod thread;
 pub mod thread_local;
 pub mod time;
@@ -49,7 +47,7 @@ pub mod stdio;
 
 #[cfg(not(target_os = "nacl"))]
 pub fn init() {
-    use libc::funcs::posix01::signal::signal;
+    use libc::signal;
     // By default, some platforms will send a *signal* when an EPIPE error
     // would otherwise be delivered. This runtime doesn't install a SIGPIPE
     // handler, causing it to kill the program, which isn't exactly what we
@@ -78,7 +76,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
         libc::EINTR => ErrorKind::Interrupted,
         libc::EINVAL => ErrorKind::InvalidInput,
         libc::ETIMEDOUT => ErrorKind::TimedOut,
-        libc::consts::os::posix88::EEXIST => ErrorKind::AlreadyExists,
+        libc::EEXIST => ErrorKind::AlreadyExists,
 
         // These two constants can have the same value on some systems,
         // but different values on others, so we can't use a match
diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs
index e4c231ff971..4e4abcfbeee 100644
--- a/src/libstd/sys/unix/mutex.rs
+++ b/src/libstd/sys/unix/mutex.rs
@@ -9,13 +9,13 @@
 // except according to those terms.
 
 use cell::UnsafeCell;
-use sys::sync as ffi;
+use libc;
 use mem;
 
-pub struct Mutex { inner: UnsafeCell<ffi::pthread_mutex_t> }
+pub struct Mutex { inner: UnsafeCell<libc::pthread_mutex_t> }
 
 #[inline]
-pub unsafe fn raw(m: &Mutex) -> *mut ffi::pthread_mutex_t {
+pub unsafe fn raw(m: &Mutex) -> *mut libc::pthread_mutex_t {
     m.inner.get()
 }
 
@@ -27,42 +27,42 @@ impl Mutex {
     pub const fn new() -> Mutex {
         // Might be moved and address is changing it is better to avoid
         // initialization of potentially opaque OS data before it landed
-        Mutex { inner: UnsafeCell::new(ffi::PTHREAD_MUTEX_INITIALIZER) }
+        Mutex { inner: UnsafeCell::new(libc::PTHREAD_MUTEX_INITIALIZER) }
     }
     #[inline]
     pub unsafe fn lock(&self) {
-        let r = ffi::pthread_mutex_lock(self.inner.get());
+        let r = libc::pthread_mutex_lock(self.inner.get());
         debug_assert_eq!(r, 0);
     }
     #[inline]
     pub unsafe fn unlock(&self) {
-        let r = ffi::pthread_mutex_unlock(self.inner.get());
+        let r = libc::pthread_mutex_unlock(self.inner.get());
         debug_assert_eq!(r, 0);
     }
     #[inline]
     pub unsafe fn try_lock(&self) -> bool {
-        ffi::pthread_mutex_trylock(self.inner.get()) == 0
+        libc::pthread_mutex_trylock(self.inner.get()) == 0
     }
     #[inline]
     #[cfg(not(target_os = "dragonfly"))]
     pub unsafe fn destroy(&self) {
-        let r = ffi::pthread_mutex_destroy(self.inner.get());
+        let r = libc::pthread_mutex_destroy(self.inner.get());
         debug_assert_eq!(r, 0);
     }
     #[inline]
     #[cfg(target_os = "dragonfly")]
     pub unsafe fn destroy(&self) {
         use libc;
-        let r = ffi::pthread_mutex_destroy(self.inner.get());
+        let r = libc::pthread_mutex_destroy(self.inner.get());
         // On DragonFly pthread_mutex_destroy() returns EINVAL if called on a
-        // mutex that was just initialized with ffi::PTHREAD_MUTEX_INITIALIZER.
+        // mutex that was just initialized with libc::PTHREAD_MUTEX_INITIALIZER.
         // Once it is used (locked/unlocked) or pthread_mutex_init() is called,
         // this behaviour no longer occurs.
         debug_assert!(r == 0 || r == libc::EINVAL);
     }
 }
 
-pub struct ReentrantMutex { inner: UnsafeCell<ffi::pthread_mutex_t> }
+pub struct ReentrantMutex { inner: UnsafeCell<libc::pthread_mutex_t> }
 
 unsafe impl Send for ReentrantMutex {}
 unsafe impl Sync for ReentrantMutex {}
@@ -73,35 +73,35 @@ impl ReentrantMutex {
     }
 
     pub unsafe fn init(&mut self) {
-        let mut attr: ffi::pthread_mutexattr_t = mem::uninitialized();
-        let result = ffi::pthread_mutexattr_init(&mut attr as *mut _);
+        let mut attr: libc::pthread_mutexattr_t = mem::uninitialized();
+        let result = libc::pthread_mutexattr_init(&mut attr as *mut _);
         debug_assert_eq!(result, 0);
-        let result = ffi::pthread_mutexattr_settype(&mut attr as *mut _,
-                                                    ffi::PTHREAD_MUTEX_RECURSIVE);
+        let result = libc::pthread_mutexattr_settype(&mut attr as *mut _,
+                                                    libc::PTHREAD_MUTEX_RECURSIVE);
         debug_assert_eq!(result, 0);
-        let result = ffi::pthread_mutex_init(self.inner.get(), &attr as *const _);
+        let result = libc::pthread_mutex_init(self.inner.get(), &attr as *const _);
         debug_assert_eq!(result, 0);
-        let result = ffi::pthread_mutexattr_destroy(&mut attr as *mut _);
+        let result = libc::pthread_mutexattr_destroy(&mut attr as *mut _);
         debug_assert_eq!(result, 0);
     }
 
     pub unsafe fn lock(&self) {
-        let result = ffi::pthread_mutex_lock(self.inner.get());
+        let result = libc::pthread_mutex_lock(self.inner.get());
         debug_assert_eq!(result, 0);
     }
 
     #[inline]
     pub unsafe fn try_lock(&self) -> bool {
-        ffi::pthread_mutex_trylock(self.inner.get()) == 0
+        libc::pthread_mutex_trylock(self.inner.get()) == 0
     }
 
     pub unsafe fn unlock(&self) {
-        let result = ffi::pthread_mutex_unlock(self.inner.get());
+        let result = libc::pthread_mutex_unlock(self.inner.get());
         debug_assert_eq!(result, 0);
     }
 
     pub unsafe fn destroy(&self) {
-        let result = ffi::pthread_mutex_destroy(self.inner.get());
+        let result = libc::pthread_mutex_destroy(self.inner.get());
         debug_assert_eq!(result, 0);
     }
 }
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index 6d65cb838f6..bcda1d651d6 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -13,16 +13,16 @@ use prelude::v1::*;
 use ffi::CStr;
 use io;
 use libc::{self, c_int, size_t};
-use net::SocketAddr;
+use net::{SocketAddr, Shutdown};
 use str;
-use sync::atomic::{self, AtomicBool};
-use sys::c;
+use sync::atomic::{AtomicBool, Ordering};
 use sys::fd::FileDesc;
 use sys_common::{AsInner, FromInner, IntoInner};
 use sys_common::net::{getsockopt, setsockopt};
 use time::Duration;
 
 pub use sys::{cvt, cvt_r};
+pub use libc as netc;
 
 pub type wrlen_t = size_t;
 
@@ -34,7 +34,7 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {
     if err == 0 { return Ok(()) }
 
     let detail = unsafe {
-        str::from_utf8(CStr::from_ptr(c::gai_strerror(err)).to_bytes()).unwrap()
+        str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap()
             .to_owned()
     };
     Err(io::Error::new(io::ErrorKind::Other,
@@ -67,29 +67,44 @@ impl Socket {
     }
 
     pub fn duplicate(&self) -> io::Result<Socket> {
-        use libc::funcs::posix88::fcntl::fcntl;
+        // We want to atomically duplicate this file descriptor and set the
+        // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
+        // flag, however, isn't supported on older Linux kernels (earlier than
+        // 2.6.24).
+        //
+        // To detect this and ensure that CLOEXEC is still set, we
+        // follow a strategy similar to musl [1] where if passing
+        // F_DUPFD_CLOEXEC causes `fcntl` to return EINVAL it means it's not
+        // supported (the third parameter, 0, is always valid), so we stop
+        // trying that. We also *still* call the `set_cloexec` method as
+        // apparently some kernel at some point stopped setting CLOEXEC even
+        // though it reported doing so on F_DUPFD_CLOEXEC.
+        //
+        // Also note that Android doesn't have F_DUPFD_CLOEXEC, but get it to
+        // resolve so we at least compile this.
+        //
+        // [1]: http://comments.gmane.org/gmane.linux.lib.musl.general/2963
+        #[cfg(target_os = "android")]
+        use libc::F_DUPFD as F_DUPFD_CLOEXEC;
+        #[cfg(not(target_os = "android"))]
+        use libc::F_DUPFD_CLOEXEC;
+
         let make_socket = |fd| {
             let fd = FileDesc::new(fd);
             fd.set_cloexec();
             Socket(fd)
         };
-        static EMULATE_F_DUPFD_CLOEXEC: AtomicBool = AtomicBool::new(false);
-        if !EMULATE_F_DUPFD_CLOEXEC.load(atomic::Ordering::Relaxed) {
-            match cvt(unsafe { fcntl(self.0.raw(), libc::F_DUPFD_CLOEXEC, 0) }) {
-                // `EINVAL` can only be returned on two occasions: Invalid
-                // command (second parameter) or invalid third parameter. 0 is
-                // always a valid third parameter, so it must be the second
-                // parameter.
-                //
-                // Store the result in a global variable so we don't try each
-                // syscall twice.
+        static TRY_CLOEXEC: AtomicBool = AtomicBool::new(true);
+        let fd = self.0.raw();
+        if !cfg!(target_os = "android") && TRY_CLOEXEC.load(Ordering::Relaxed) {
+            match cvt(unsafe { libc::fcntl(fd, F_DUPFD_CLOEXEC, 0) }) {
                 Err(ref e) if e.raw_os_error() == Some(libc::EINVAL) => {
-                    EMULATE_F_DUPFD_CLOEXEC.store(true, atomic::Ordering::Relaxed);
+                    TRY_CLOEXEC.store(false, Ordering::Relaxed);
                 }
                 res => return res.map(make_socket),
             }
         }
-        cvt(unsafe { fcntl(self.0.raw(), libc::F_DUPFD, 0) }).map(make_socket)
+        cvt(unsafe { libc::fcntl(fd, libc::F_DUPFD, 0) }).map(make_socket)
     }
 
     pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
@@ -138,6 +153,16 @@ impl Socket {
             Ok(Some(Duration::new(sec, nsec)))
         }
     }
+
+    pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
+        let how = match how {
+            Shutdown::Write => libc::SHUT_WR,
+            Shutdown::Read => libc::SHUT_RD,
+            Shutdown::Both => libc::SHUT_RDWR,
+        };
+        try!(cvt(unsafe { libc::shutdown(self.0.raw(), how) }));
+        Ok(())
+    }
 }
 
 impl AsInner<c_int> for Socket {
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index 4e7058d0687..3c53db53f85 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -27,9 +27,8 @@ use ptr;
 use slice;
 use str;
 use sync::StaticMutex;
-use sys::c;
-use sys::fd;
 use sys::cvt;
+use sys::fd;
 use vec;
 
 const TMPBUF_SZ: usize = 128;
@@ -230,8 +229,11 @@ pub fn current_exe() -> io::Result<PathBuf> {
 
 #[cfg(any(target_os = "macos", target_os = "ios"))]
 pub fn current_exe() -> io::Result<PathBuf> {
+    extern {
+        fn _NSGetExecutablePath(buf: *mut libc::c_char,
+                                bufsize: *mut u32) -> libc::c_int;
+    }
     unsafe {
-        use libc::funcs::extra::_NSGetExecutablePath;
         let mut sz: u32 = 0;
         _NSGetExecutablePath(ptr::null_mut(), &mut sz);
         if sz == 0 { return Err(io::Error::last_os_error()); }
@@ -425,7 +427,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
     let v = try!(CString::new(v.as_bytes()));
     let _g = ENV_LOCK.lock();
     cvt(unsafe {
-        libc::funcs::posix01::unistd::setenv(k.as_ptr(), v.as_ptr(), 1)
+        libc::setenv(k.as_ptr(), v.as_ptr(), 1)
     }).map(|_| ())
 }
 
@@ -433,7 +435,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
     let nbuf = try!(CString::new(n.as_bytes()));
     let _g = ENV_LOCK.lock();
     cvt(unsafe {
-        libc::funcs::posix01::unistd::unsetenv(nbuf.as_ptr())
+        libc::unsetenv(nbuf.as_ptr())
     }).map(|_| ())
 }
 
@@ -466,18 +468,18 @@ pub fn home_dir() -> Option<PathBuf> {
                   target_os = "ios",
                   target_os = "nacl")))]
     unsafe fn fallback() -> Option<OsString> {
-        let amt = match libc::sysconf(c::_SC_GETPW_R_SIZE_MAX) {
+        let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {
             n if n < 0 => 512 as usize,
             n => n as usize,
         };
         let me = libc::getuid();
         loop {
             let mut buf = Vec::with_capacity(amt);
-            let mut passwd: c::passwd = mem::zeroed();
+            let mut passwd: libc::passwd = mem::zeroed();
             let mut result = ptr::null_mut();
-            match c::getpwuid_r(me, &mut passwd, buf.as_mut_ptr(),
-                                buf.capacity() as libc::size_t,
-                                &mut result) {
+            match libc::getpwuid_r(me, &mut passwd, buf.as_mut_ptr(),
+                                   buf.capacity() as libc::size_t,
+                                   &mut result) {
                 0 if !result.is_null() => {}
                 _ => return None
             }
diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs
index 7e37238c23b..8d80296ab03 100644
--- a/src/libstd/sys/unix/process.rs
+++ b/src/libstd/sys/unix/process.rs
@@ -23,7 +23,7 @@ use ptr;
 use sys::fd::FileDesc;
 use sys::fs::{File, OpenOptions};
 use sys::pipe::AnonPipe;
-use sys::{self, c, cvt, cvt_r};
+use sys::{self, cvt, cvt_r};
 
 ////////////////////////////////////////////////////////////////////////////////
 // Command
@@ -163,7 +163,7 @@ const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX";
 
 impl Process {
     pub unsafe fn kill(&self) -> io::Result<()> {
-        try!(cvt(libc::funcs::posix88::signal::kill(self.pid, libc::SIGKILL)));
+        try!(cvt(libc::kill(self.pid, libc::SIGKILL)));
         Ok(())
     }
 
@@ -326,7 +326,7 @@ impl Process {
             // fail if we aren't root, so don't bother checking the
             // return value, this is just done as an optimistic
             // privilege dropping function.
-            let _ = c::setgroups(0, ptr::null());
+            let _ = libc::setgroups(0, ptr::null());
 
             if libc::setuid(u as libc::uid_t) != 0 {
                 fail(&mut output);
@@ -355,12 +355,12 @@ impl Process {
             // UNIX programs do not reset these things on their own, so we
             // need to clean things up now to avoid confusing the program
             // we're about to run.
-            let mut set: c::sigset_t = mem::uninitialized();
-            if c::sigemptyset(&mut set) != 0 ||
-                c::pthread_sigmask(c::SIG_SETMASK, &set, ptr::null_mut()) != 0 ||
-                libc::funcs::posix01::signal::signal(
-                    libc::SIGPIPE, mem::transmute(c::SIG_DFL)
-                        ) == mem::transmute(c::SIG_ERR)
+            let mut set: libc::sigset_t = mem::uninitialized();
+            if libc::sigemptyset(&mut set) != 0 ||
+                libc::pthread_sigmask(libc::SIG_SETMASK, &set, ptr::null_mut()) != 0 ||
+                libc::signal(
+                    libc::SIGPIPE, mem::transmute(libc::SIG_DFL)
+                        ) == mem::transmute(libc::SIG_ERR)
             {
                 fail(output);
             }
@@ -381,14 +381,14 @@ impl Process {
 
     pub fn wait(&self) -> io::Result<ExitStatus> {
         let mut status = 0 as c_int;
-        try!(cvt_r(|| unsafe { c::waitpid(self.pid, &mut status, 0) }));
+        try!(cvt_r(|| unsafe { libc::waitpid(self.pid, &mut status, 0) }));
         Ok(ExitStatus(status))
     }
 
     pub fn try_wait(&self) -> Option<ExitStatus> {
         let mut status = 0 as c_int;
         match cvt_r(|| unsafe {
-            c::waitpid(self.pid, &mut status, c::WNOHANG)
+            libc::waitpid(self.pid, &mut status, libc::WNOHANG)
         }) {
             Ok(0) => None,
             Ok(n) if n == self.pid => Some(ExitStatus(status)),
@@ -459,7 +459,7 @@ mod tests {
     use ptr;
     use libc;
     use slice;
-    use sys::{self, c, cvt, pipe};
+    use sys::{self, cvt, pipe};
 
     macro_rules! t {
         ($e:expr) => {
@@ -473,12 +473,12 @@ mod tests {
     #[cfg(not(target_os = "android"))]
     extern {
         #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
-        fn sigaddset(set: *mut c::sigset_t, signum: libc::c_int) -> libc::c_int;
+        fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int;
     }
 
     #[cfg(target_os = "android")]
-    unsafe fn sigaddset(set: *mut c::sigset_t, signum: libc::c_int) -> libc::c_int {
-        let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::<c::sigset_t>());
+    unsafe fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int {
+        let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::<libc::sigset_t>());
         let bit = (signum - 1) as usize;
         raw[bit / 8] |= 1 << (bit % 8);
         return 0;
@@ -497,11 +497,11 @@ mod tests {
             let (stdin_read, stdin_write) = t!(sys::pipe::anon_pipe());
             let (stdout_read, stdout_write) = t!(sys::pipe::anon_pipe());
 
-            let mut set: c::sigset_t = mem::uninitialized();
-            let mut old_set: c::sigset_t = mem::uninitialized();
-            t!(cvt(c::sigemptyset(&mut set)));
+            let mut set: libc::sigset_t = mem::uninitialized();
+            let mut old_set: libc::sigset_t = mem::uninitialized();
+            t!(cvt(libc::sigemptyset(&mut set)));
             t!(cvt(sigaddset(&mut set, libc::SIGINT)));
-            t!(cvt(c::pthread_sigmask(c::SIG_SETMASK, &set, &mut old_set)));
+            t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, &mut old_set)));
 
             let cat = t!(Process::spawn(&cmd, Stdio::Raw(stdin_read.raw()),
                                               Stdio::Raw(stdout_write.raw()),
@@ -509,11 +509,10 @@ mod tests {
             drop(stdin_read);
             drop(stdout_write);
 
-            t!(cvt(c::pthread_sigmask(c::SIG_SETMASK, &old_set,
-                                      ptr::null_mut())));
+            t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &old_set,
+                                         ptr::null_mut())));
 
-            t!(cvt(libc::funcs::posix88::signal::kill(cat.id() as libc::pid_t,
-                                                      libc::SIGINT)));
+            t!(cvt(libc::kill(cat.id() as libc::pid_t, libc::SIGINT)));
             // We need to wait until SIGINT is definitely delivered. The
             // easiest way is to write something to cat, and try to read it
             // back: if SIGINT is unmasked, it'll get delivered when cat is
diff --git a/src/libstd/sys/unix/rwlock.rs b/src/libstd/sys/unix/rwlock.rs
index 788bff62430..44bd5d895f2 100644
--- a/src/libstd/sys/unix/rwlock.rs
+++ b/src/libstd/sys/unix/rwlock.rs
@@ -10,20 +10,19 @@
 
 use libc;
 use cell::UnsafeCell;
-use sys::sync as ffi;
 
-pub struct RWLock { inner: UnsafeCell<ffi::pthread_rwlock_t> }
+pub struct RWLock { inner: UnsafeCell<libc::pthread_rwlock_t> }
 
 unsafe impl Send for RWLock {}
 unsafe impl Sync for RWLock {}
 
 impl RWLock {
     pub const fn new() -> RWLock {
-        RWLock { inner: UnsafeCell::new(ffi::PTHREAD_RWLOCK_INITIALIZER) }
+        RWLock { inner: UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER) }
     }
     #[inline]
     pub unsafe fn read(&self) {
-        let r = ffi::pthread_rwlock_rdlock(self.inner.get());
+        let r = libc::pthread_rwlock_rdlock(self.inner.get());
 
         // According to the pthread_rwlock_rdlock spec, this function **may**
         // fail with EDEADLK if a deadlock is detected. On the other hand
@@ -44,11 +43,11 @@ impl RWLock {
     }
     #[inline]
     pub unsafe fn try_read(&self) -> bool {
-        ffi::pthread_rwlock_tryrdlock(self.inner.get()) == 0
+        libc::pthread_rwlock_tryrdlock(self.inner.get()) == 0
     }
     #[inline]
     pub unsafe fn write(&self) {
-        let r = ffi::pthread_rwlock_wrlock(self.inner.get());
+        let r = libc::pthread_rwlock_wrlock(self.inner.get());
         // see comments above for why we check for EDEADLK
         if r == libc::EDEADLK {
             panic!("rwlock write lock would result in deadlock");
@@ -58,21 +57,21 @@ impl RWLock {
     }
     #[inline]
     pub unsafe fn try_write(&self) -> bool {
-        ffi::pthread_rwlock_trywrlock(self.inner.get()) == 0
+        libc::pthread_rwlock_trywrlock(self.inner.get()) == 0
     }
     #[inline]
     pub unsafe fn read_unlock(&self) {
-        let r = ffi::pthread_rwlock_unlock(self.inner.get());
+        let r = libc::pthread_rwlock_unlock(self.inner.get());
         debug_assert_eq!(r, 0);
     }
     #[inline]
     pub unsafe fn write_unlock(&self) { self.read_unlock() }
     #[inline]
     pub unsafe fn destroy(&self) {
-        let r = ffi::pthread_rwlock_destroy(self.inner.get());
+        let r = libc::pthread_rwlock_destroy(self.inner.get());
         // On DragonFly pthread_rwlock_destroy() returns EINVAL if called on a
         // rwlock that was just initialized with
-        // ffi::PTHREAD_RWLOCK_INITIALIZER. Once it is used (locked/unlocked)
+        // libc::PTHREAD_RWLOCK_INITIALIZER. Once it is used (locked/unlocked)
         // or pthread_rwlock_init() is called, this behaviour no longer occurs.
         if cfg!(target_os = "dragonfly") {
             debug_assert!(r == 0 || r == libc::EINVAL);
diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs
index 5f624bc76b3..9a7f98d24cd 100644
--- a/src/libstd/sys/unix/stack_overflow.rs
+++ b/src/libstd/sys/unix/stack_overflow.rs
@@ -43,11 +43,11 @@ mod imp {
     use sys_common::util::report_overflow;
     use mem;
     use ptr;
-    use sys::c::{siginfo, sigaction, SIGBUS, SIG_DFL,
-                 SA_SIGINFO, SA_ONSTACK, sigaltstack,
-                 SIGSTKSZ, sighandler_t};
+    use libc::{sigaction, SIGBUS, SIG_DFL,
+               SA_SIGINFO, SA_ONSTACK, sigaltstack,
+               SIGSTKSZ, sighandler_t};
     use libc;
-    use libc::funcs::posix88::mman::{mmap, munmap};
+    use libc::{mmap, munmap};
     use libc::{SIGSEGV, PROT_READ, PROT_WRITE, MAP_PRIVATE, MAP_ANON};
     use libc::MAP_FAILED;
 
@@ -57,6 +57,22 @@ mod imp {
     // This is initialized in init() and only read from after
     static mut PAGE_SIZE: usize = 0;
 
+    #[cfg(any(target_os = "linux", target_os = "android"))]
+    unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> *mut libc::c_void {
+        #[repr(C)]
+        struct siginfo_t {
+            a: [libc::c_int; 3], // si_signo, si_code, si_errno,
+            si_addr: *mut libc::c_void,
+        }
+
+        (*(info as *const siginfo_t)).si_addr
+    }
+
+    #[cfg(not(any(target_os = "linux", target_os = "android")))]
+    unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> *mut libc::c_void {
+        (*info).si_addr
+    }
+
     // Signal handler for the SIGSEGV and SIGBUS handlers. We've got guard pages
     // (unmapped pages) at the end of every thread's stack, so if a thread ends
     // up running into the guard page it'll trigger this handler. We want to
@@ -76,10 +92,10 @@ mod imp {
     // handler to work. For a more detailed explanation see the comments on
     // #26458.
     unsafe extern fn signal_handler(signum: libc::c_int,
-                                    info: *mut siginfo,
+                                    info: *mut libc::siginfo_t,
                                     _data: *mut libc::c_void) {
         let guard = thread_info::stack_guard().unwrap_or(0);
-        let addr = (*info).si_addr as usize;
+        let addr = siginfo_si_addr(info) as usize;
 
         // If the faulting address is within the guard page, then we print a
         // message saying so.
@@ -126,7 +142,7 @@ mod imp {
             panic!("failed to allocate an alternative stack");
         }
 
-        let mut stack: sigaltstack = mem::zeroed();
+        let mut stack: libc::stack_t = mem::zeroed();
 
         stack.ss_sp = alt_stack;
         stack.ss_flags = 0;
diff --git a/src/libstd/sys/unix/sync.rs b/src/libstd/sys/unix/sync.rs
deleted file mode 100644
index 6f6acc2560e..00000000000
--- a/src/libstd/sys/unix/sync.rs
+++ /dev/null
@@ -1,374 +0,0 @@
-// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![allow(bad_style)]
-
-use libc;
-
-pub use self::os::{PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_RECURSIVE, pthread_mutex_t,
-                   pthread_mutexattr_t};
-pub use self::os::{PTHREAD_COND_INITIALIZER, pthread_cond_t};
-pub use self::os::{PTHREAD_RWLOCK_INITIALIZER, pthread_rwlock_t};
-
-extern {
-    // mutexes
-    pub fn pthread_mutex_init(lock: *mut pthread_mutex_t, attr: *const pthread_mutexattr_t)
-                            -> libc::c_int;
-    pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> libc::c_int;
-    pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> libc::c_int;
-    pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> libc::c_int;
-    pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> libc::c_int;
-
-    pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> libc::c_int;
-    pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> libc::c_int;
-    pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t, _type: libc::c_int)
-                                    -> libc::c_int;
-
-    // cvars
-    pub fn pthread_cond_wait(cond: *mut pthread_cond_t,
-                             lock: *mut pthread_mutex_t) -> libc::c_int;
-    #[cfg_attr(target_os = "nacl", link_name = "pthread_cond_timedwait_abs")]
-    pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t,
-                              lock: *mut pthread_mutex_t,
-                              abstime: *const libc::timespec) -> libc::c_int;
-    pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> libc::c_int;
-    pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> libc::c_int;
-    pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int;
-    #[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")]
-    pub fn gettimeofday(tp: *mut libc::timeval,
-                        tz: *mut libc::c_void) -> libc::c_int;
-
-    // rwlocks
-    pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> libc::c_int;
-    pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
-    pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
-    pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
-    pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
-    pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
-}
-
-#[cfg(any(target_os = "freebsd",
-          target_os = "dragonfly",
-          target_os = "bitrig",
-          target_os = "openbsd"))]
-mod os {
-    use libc;
-    use ptr;
-
-    pub type pthread_mutex_t = *mut libc::c_void;
-    pub type pthread_mutexattr_t = *mut libc::c_void;
-    pub type pthread_cond_t = *mut libc::c_void;
-    pub type pthread_rwlock_t = *mut libc::c_void;
-
-    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = ptr::null_mut();
-    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = ptr::null_mut();
-    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = ptr::null_mut();
-    pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2;
-}
-
-#[cfg(any(target_os = "macos", target_os = "ios"))]
-mod os {
-    use libc;
-
-    #[cfg(any(target_arch = "x86_64",
-              target_arch = "aarch64"))]
-    const __PTHREAD_MUTEX_SIZE__: usize = 56;
-    #[cfg(any(target_arch = "x86",
-              target_arch = "arm"))]
-    const __PTHREAD_MUTEX_SIZE__: usize = 40;
-
-    #[cfg(any(target_arch = "x86_64",
-              target_arch = "aarch64"))]
-    const __PTHREAD_COND_SIZE__: usize = 40;
-    #[cfg(any(target_arch = "x86",
-              target_arch = "arm"))]
-    const __PTHREAD_COND_SIZE__: usize = 24;
-
-    #[cfg(any(target_arch = "x86_64",
-              target_arch = "aarch64"))]
-    const __PTHREAD_RWLOCK_SIZE__: usize = 192;
-    #[cfg(any(target_arch = "x86",
-              target_arch = "arm"))]
-    const __PTHREAD_RWLOCK_SIZE__: usize = 124;
-
-    const _PTHREAD_MUTEX_SIG_INIT: libc::c_long = 0x32AAABA7;
-    const _PTHREAD_COND_SIG_INIT: libc::c_long = 0x3CB0B1BB;
-    const _PTHREAD_RWLOCK_SIG_INIT: libc::c_long = 0x2DA8B3B4;
-
-    #[repr(C)]
-    pub struct pthread_mutex_t {
-        __sig: libc::c_long,
-        __opaque: [u8; __PTHREAD_MUTEX_SIZE__],
-    }
-    #[repr(C)]
-    pub struct pthread_mutexattr_t {
-        __sig: libc::c_long,
-        // note, that this is 16 bytes just to be safe, the actual struct might be smaller.
-        __opaque: [u8; 16],
-    }
-    #[repr(C)]
-    pub struct pthread_cond_t {
-        __sig: libc::c_long,
-        __opaque: [u8; __PTHREAD_COND_SIZE__],
-    }
-    #[repr(C)]
-    pub struct pthread_rwlock_t {
-        __sig: libc::c_long,
-        __opaque: [u8; __PTHREAD_RWLOCK_SIZE__],
-    }
-
-    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
-        __sig: _PTHREAD_MUTEX_SIG_INIT,
-        __opaque: [0; __PTHREAD_MUTEX_SIZE__],
-    };
-    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
-        __sig: _PTHREAD_COND_SIG_INIT,
-        __opaque: [0; __PTHREAD_COND_SIZE__],
-    };
-    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
-        __sig: _PTHREAD_RWLOCK_SIG_INIT,
-        __opaque: [0; __PTHREAD_RWLOCK_SIZE__],
-    };
-
-    pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2;
-}
-
-#[cfg(target_os = "linux")]
-mod os {
-    use libc;
-
-    // minus 8 because we have an 'align' field
-    #[cfg(target_arch = "x86_64")]
-    const __SIZEOF_PTHREAD_MUTEX_T: usize = 40 - 8;
-    #[cfg(any(target_arch = "x86",
-              target_arch = "arm",
-              target_arch = "mips",
-              target_arch = "mipsel",
-              target_arch = "powerpc"))]
-    const __SIZEOF_PTHREAD_MUTEX_T: usize = 24 - 8;
-    #[cfg(target_arch = "aarch64")]
-    const __SIZEOF_PTHREAD_MUTEX_T: usize = 48 - 8;
-
-    #[cfg(any(target_arch = "x86_64",
-              target_arch = "x86",
-              target_arch = "arm",
-              target_arch = "aarch64",
-              target_arch = "mips",
-              target_arch = "mipsel",
-              target_arch = "powerpc"))]
-    const __SIZEOF_PTHREAD_COND_T: usize = 48 - 8;
-
-    #[cfg(any(target_arch = "x86_64",
-              target_arch = "aarch64"))]
-    const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56 - 8;
-
-    #[cfg(any(target_arch = "x86",
-              target_arch = "arm",
-              target_arch = "mips",
-              target_arch = "mipsel",
-              target_arch = "powerpc"))]
-    const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32 - 8;
-
-    #[repr(C)]
-    pub struct pthread_mutex_t {
-        __align: libc::c_longlong,
-        size: [u8; __SIZEOF_PTHREAD_MUTEX_T],
-    }
-    #[repr(C)]
-    pub struct pthread_mutexattr_t {
-        __align: libc::c_longlong,
-        // note, that this is 16 bytes just to be safe, the actual struct might be smaller.
-        size: [u8; 16],
-    }
-    #[repr(C)]
-    pub struct pthread_cond_t {
-        __align: libc::c_longlong,
-        size: [u8; __SIZEOF_PTHREAD_COND_T],
-    }
-    #[repr(C)]
-    pub struct pthread_rwlock_t {
-        __align: libc::c_longlong,
-        size: [u8; __SIZEOF_PTHREAD_RWLOCK_T],
-    }
-
-    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
-        __align: 0,
-        size: [0; __SIZEOF_PTHREAD_MUTEX_T],
-    };
-    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
-        __align: 0,
-        size: [0; __SIZEOF_PTHREAD_COND_T],
-    };
-    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
-        __align: 0,
-        size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
-    };
-    pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 1;
-}
-#[cfg(target_os = "android")]
-mod os {
-    use libc;
-    use ptr;
-
-    #[repr(C)]
-    pub struct pthread_mutex_t { value: libc::c_int }
-    pub type pthread_mutexattr_t = libc::c_long;
-    #[repr(C)]
-    pub struct pthread_cond_t { value: libc::c_int }
-    #[repr(C)]
-    pub struct pthread_rwlock_t {
-        lock: pthread_mutex_t,
-        cond: pthread_cond_t,
-        numLocks: libc::c_int,
-        writerThreadId: libc::c_int,
-        pendingReaders: libc::c_int,
-        pendingWriters: libc::c_int,
-        reserved: [*mut libc::c_void; 4],
-    }
-
-    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
-        value: 0,
-    };
-    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
-        value: 0,
-    };
-    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
-        lock: PTHREAD_MUTEX_INITIALIZER,
-        cond: PTHREAD_COND_INITIALIZER,
-        numLocks: 0,
-        writerThreadId: 0,
-        pendingReaders: 0,
-        pendingWriters: 0,
-        reserved: [ptr::null_mut(); 4],
-    };
-    pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 1;
-}
-
-#[cfg(target_os = "netbsd")]
-mod os {
-    use libc;
-
-    // size of the type minus width of the magic and alignment field
-    #[cfg(target_arch = "x86_64")]
-    const __PTHREAD_MUTEX_SIZE__: usize = 48 - 4 - 8;
-
-    #[cfg(target_arch = "x86_64")]
-    const __PTHREAD_MUTEXATTR_SIZE__: usize = 16 - 8; // no magic field
-
-    #[cfg(target_arch = "x86_64")]
-    const __PTHREAD_COND_SIZE__: usize = 40 - 4 - 8;
-
-    #[cfg(target_arch = "x86_64")]
-    const __PTHREAD_RWLOCK_SIZE__: usize = 64 - 4 - 8;
-
-    const _PTHREAD_MUTEX_MAGIC_INIT: libc::c_uint = 0x33330003;
-    const _PTHREAD_COND_MAGIC_INIT: libc::c_uint = 0x55550005;
-    const _PTHREAD_RWLOCK_MAGIC_INIT: libc::c_uint = 0x99990009;
-
-    #[repr(C)]
-    pub struct pthread_mutex_t {
-        __magic: libc::c_uint,
-        __opaque: [u8; __PTHREAD_MUTEX_SIZE__],
-        __align: libc::c_longlong,
-    }
-    #[repr(C)]
-    pub struct pthread_mutexattr_t {
-        __opaque: [u8; __PTHREAD_MUTEXATTR_SIZE__],
-        __align: libc::c_longlong,
-    }
-    #[repr(C)]
-    pub struct pthread_cond_t {
-        __magic: libc::c_uint,
-        __opaque: [u8; __PTHREAD_COND_SIZE__],
-        __align: libc::c_longlong,
-    }
-    #[repr(C)]
-    pub struct pthread_rwlock_t {
-        __magic: libc::c_uint,
-        __opaque: [u8; __PTHREAD_RWLOCK_SIZE__],
-        __align: libc::c_longlong,
-    }
-
-    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
-        __magic: _PTHREAD_MUTEX_MAGIC_INIT,
-        __opaque: [0; __PTHREAD_MUTEX_SIZE__],
-        __align: 0,
-    };
-    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
-        __magic: _PTHREAD_COND_MAGIC_INIT,
-        __opaque: [0; __PTHREAD_COND_SIZE__],
-        __align: 0,
-    };
-    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
-        __magic: _PTHREAD_RWLOCK_MAGIC_INIT,
-        __opaque: [0; __PTHREAD_RWLOCK_SIZE__],
-        __align: 0,
-    };
-
-    pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2;
-}
-#[cfg(target_os = "nacl")]
-mod os {
-    use libc;
-
-    pub type __nc_basic_thread_data = libc::c_void;
-
-    #[repr(C)]
-    pub struct pthread_mutex_t {
-        mutex_state: libc::c_int,
-        mutex_type: libc::c_int,
-        owner_thread_id: *mut __nc_basic_thread_data,
-        recursion_counter: libc::uint32_t,
-        _unused: libc::c_int,
-    }
-    #[repr(C)]
-    pub struct pthread_mutexattr_t {
-        kind: libc::c_int,
-    }
-    #[repr(C)]
-    pub struct pthread_cond_t {
-        sequence_number: libc::c_int,
-        _unused: libc::c_int,
-    }
-    #[repr(C)]
-    pub struct pthread_rwlock_t {
-        mutex: pthread_mutex_t,
-        reader_count: libc::c_int,
-        writers_waiting: libc::c_int,
-        writer_thread_id: *mut __nc_basic_thread_data,
-        read_possible: pthread_cond_t,
-        write_possible: pthread_cond_t,
-    }
-
-    const NC_INVALID_HANDLE: libc::c_int = -1;
-    const NACL_PTHREAD_ILLEGAL_THREAD_ID: *mut __nc_basic_thread_data
-        = 0 as *mut __nc_basic_thread_data;
-
-    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
-        mutex_state:       0,
-        mutex_type:        0,
-        owner_thread_id:   NACL_PTHREAD_ILLEGAL_THREAD_ID,
-        recursion_counter: 0,
-        _unused:           NC_INVALID_HANDLE,
-    };
-    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
-        sequence_number: 0,
-        _unused: NC_INVALID_HANDLE,
-    };
-    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
-        mutex: PTHREAD_MUTEX_INITIALIZER,
-        reader_count: 0,
-        writers_waiting: 0,
-        writer_thread_id: NACL_PTHREAD_ILLEGAL_THREAD_ID,
-        read_possible: PTHREAD_COND_INITIALIZER,
-        write_possible: PTHREAD_COND_INITIALIZER,
-    };
-    pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 1;
-}
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index 3eedb76c21b..f111f97be60 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -17,7 +17,7 @@ use cmp;
 #[cfg(not(target_env = "newlib"))]
 use ffi::CString;
 use io;
-use libc::consts::os::posix01::PTHREAD_STACK_MIN;
+use libc::PTHREAD_STACK_MIN;
 use libc;
 use mem;
 use ptr;
@@ -41,10 +41,11 @@ impl Thread {
         let p = box p;
         let mut native: libc::pthread_t = mem::zeroed();
         let mut attr: libc::pthread_attr_t = mem::zeroed();
-        assert_eq!(pthread_attr_init(&mut attr), 0);
+        assert_eq!(libc::pthread_attr_init(&mut attr), 0);
 
         let stack_size = cmp::max(stack, min_stack_size(&attr));
-        match pthread_attr_setstacksize(&mut attr, stack_size as libc::size_t) {
+        match libc::pthread_attr_setstacksize(&mut attr,
+                                              stack_size as libc::size_t) {
             0 => {}
             n => {
                 assert_eq!(n, libc::EINVAL);
@@ -56,13 +57,14 @@ impl Thread {
                 let stack_size = (stack_size + page_size - 1) &
                                  (-(page_size as isize - 1) as usize - 1);
                 let stack_size = stack_size as libc::size_t;
-                assert_eq!(pthread_attr_setstacksize(&mut attr, stack_size), 0);
+                assert_eq!(libc::pthread_attr_setstacksize(&mut attr,
+                                                           stack_size), 0);
             }
         };
 
-        let ret = pthread_create(&mut native, &attr, thread_start,
-                                 &*p as *const _ as *mut _);
-        assert_eq!(pthread_attr_destroy(&mut attr), 0);
+        let ret = libc::pthread_create(&mut native, &attr, thread_start,
+                                       &*p as *const _ as *mut _);
+        assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
 
         return if ret != 0 {
             Err(io::Error::from_raw_os_error(ret))
@@ -78,25 +80,20 @@ impl Thread {
     }
 
     pub fn yield_now() {
-        let ret = unsafe { sched_yield() };
+        let ret = unsafe { libc::sched_yield() };
         debug_assert_eq!(ret, 0);
     }
 
     #[cfg(any(target_os = "linux", target_os = "android"))]
     pub fn set_name(name: &str) {
-        // pthread wrapper only appeared in glibc 2.12, so we use syscall
-        // directly.
-        extern {
-            fn prctl(option: libc::c_int, arg2: libc::c_ulong,
-                     arg3: libc::c_ulong, arg4: libc::c_ulong,
-                     arg5: libc::c_ulong) -> libc::c_int;
-        }
         const PR_SET_NAME: libc::c_int = 15;
         let cname = CString::new(name).unwrap_or_else(|_| {
             panic!("thread name may not contain interior null bytes")
         });
+        // pthread wrapper only appeared in glibc 2.12, so we use syscall
+        // directly.
         unsafe {
-            prctl(PR_SET_NAME, cname.as_ptr() as libc::c_ulong, 0, 0, 0);
+            libc::prctl(PR_SET_NAME, cname.as_ptr() as libc::c_ulong, 0, 0, 0);
         }
     }
 
@@ -105,39 +102,27 @@ impl Thread {
               target_os = "bitrig",
               target_os = "openbsd"))]
     pub fn set_name(name: &str) {
-        extern {
-            fn pthread_set_name_np(tid: libc::pthread_t,
-                                   name: *const libc::c_char);
-        }
         let cname = CString::new(name).unwrap();
         unsafe {
-            pthread_set_name_np(pthread_self(), cname.as_ptr());
+            libc::pthread_set_name_np(libc::pthread_self(), cname.as_ptr());
         }
     }
 
     #[cfg(any(target_os = "macos", target_os = "ios"))]
     pub fn set_name(name: &str) {
-        extern {
-            fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int;
-        }
         let cname = CString::new(name).unwrap();
         unsafe {
-            pthread_setname_np(cname.as_ptr());
+            libc::pthread_setname_np(cname.as_ptr());
         }
     }
 
     #[cfg(target_os = "netbsd")]
     pub fn set_name(name: &str) {
-        extern {
-            fn pthread_setname_np(thread: libc::pthread_t,
-                                  name: *const libc::c_char,
-                                  arg: *mut libc::c_void) -> libc::c_int;
-        }
         let cname = CString::new(&b"%s"[..]).unwrap();
         let carg = CString::new(name).unwrap();
         unsafe {
-            pthread_setname_np(pthread_self(), cname.as_ptr(),
-                               carg.as_ptr() as *mut libc::c_void);
+            libc::pthread_setname_np(libc::pthread_self(), cname.as_ptr(),
+                                     carg.as_ptr() as *mut libc::c_void);
         }
     }
     #[cfg(target_env = "newlib")]
@@ -162,7 +147,7 @@ impl Thread {
 
     pub fn join(self) {
         unsafe {
-            let ret = pthread_join(self.id, ptr::null_mut());
+            let ret = libc::pthread_join(self.id, ptr::null_mut());
             mem::forget(self);
             debug_assert_eq!(ret, 0);
         }
@@ -171,7 +156,7 @@ impl Thread {
 
 impl Drop for Thread {
     fn drop(&mut self) {
-        let ret = unsafe { pthread_detach(self.id) };
+        let ret = unsafe { libc::pthread_detach(self.id) };
         debug_assert_eq!(ret, 0);
     }
 }
@@ -197,15 +182,10 @@ pub mod guard {
     use prelude::v1::*;
 
     use libc::{self, pthread_t};
-    use libc::funcs::posix88::mman::mmap;
-    use libc::consts::os::posix88::{PROT_NONE,
-                                    MAP_PRIVATE,
-                                    MAP_ANON,
-                                    MAP_FAILED,
-                                    MAP_FIXED};
+    use libc::mmap;
+    use libc::{PROT_NONE, MAP_PRIVATE, MAP_ANON, MAP_FAILED, MAP_FIXED};
     use mem;
     use ptr;
-    use super::{pthread_self, pthread_attr_destroy};
     use sys::os;
 
     #[cfg(any(target_os = "macos",
@@ -217,19 +197,17 @@ pub mod guard {
 
     #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
     unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
-        use super::pthread_attr_init;
-
         let mut ret = None;
         let mut attr: libc::pthread_attr_t = mem::zeroed();
-        assert_eq!(pthread_attr_init(&mut attr), 0);
-        if pthread_getattr_np(pthread_self(), &mut attr) == 0 {
+        assert_eq!(libc::pthread_attr_init(&mut attr), 0);
+        if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
             let mut stackaddr = ptr::null_mut();
             let mut stacksize = 0;
-            assert_eq!(pthread_attr_getstack(&attr, &mut stackaddr,
-                                             &mut stacksize), 0);
+            assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
+                                                   &mut stacksize), 0);
             ret = Some(stackaddr);
         }
-        assert_eq!(pthread_attr_destroy(&mut attr), 0);
+        assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
         ret
     }
 
@@ -273,33 +251,18 @@ pub mod guard {
 
     #[cfg(target_os = "macos")]
     pub unsafe fn current() -> Option<usize> {
-        extern {
-            fn pthread_get_stackaddr_np(thread: pthread_t) -> *mut libc::c_void;
-            fn pthread_get_stacksize_np(thread: pthread_t) -> libc::size_t;
-        }
-        Some((pthread_get_stackaddr_np(pthread_self()) as libc::size_t -
-              pthread_get_stacksize_np(pthread_self())) as usize)
+        Some((libc::pthread_get_stackaddr_np(libc::pthread_self()) as libc::size_t -
+              libc::pthread_get_stacksize_np(libc::pthread_self())) as usize)
     }
 
     #[cfg(any(target_os = "openbsd", target_os = "bitrig"))]
     pub unsafe fn current() -> Option<usize> {
-        #[repr(C)]
-        struct stack_t {
-            ss_sp: *mut libc::c_void,
-            ss_size: libc::size_t,
-            ss_flags: libc::c_int,
-        }
-        extern {
-            fn pthread_main_np() -> libc::c_uint;
-            fn pthread_stackseg_np(thread: pthread_t,
-                                   sinfo: *mut stack_t) -> libc::c_uint;
-        }
-
-        let mut current_stack: stack_t = mem::zeroed();
-        assert_eq!(pthread_stackseg_np(pthread_self(), &mut current_stack), 0);
+        let mut current_stack: libc::stack_t = mem::zeroed();
+        assert_eq!(libc::pthread_stackseg_np(libc::pthread_self(),
+                                             &mut current_stack), 0);
 
         let extra = if cfg!(target_os = "bitrig") {3} else {1} * os::page_size();
-        Some(if pthread_main_np() == 1 {
+        Some(if libc::pthread_main_np() == 1 {
             // main thread
             current_stack.ss_sp as usize - current_stack.ss_size as usize + extra
         } else {
@@ -310,20 +273,19 @@ pub mod guard {
 
     #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
     pub unsafe fn current() -> Option<usize> {
-        use super::pthread_attr_init;
-
         let mut ret = None;
         let mut attr: libc::pthread_attr_t = mem::zeroed();
-        assert_eq!(pthread_attr_init(&mut attr), 0);
-        if pthread_getattr_np(pthread_self(), &mut attr) == 0 {
+        assert_eq!(libc::pthread_attr_init(&mut attr), 0);
+        if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
             let mut guardsize = 0;
-            assert_eq!(pthread_attr_getguardsize(&attr, &mut guardsize), 0);
+            assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0);
             if guardsize == 0 {
                 panic!("there is no guard page");
             }
             let mut stackaddr = ptr::null_mut();
             let mut size = 0;
-            assert_eq!(pthread_attr_getstack(&attr, &mut stackaddr, &mut size), 0);
+            assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
+                                                   &mut size), 0);
 
             ret = if cfg!(target_os = "netbsd") {
                 Some(stackaddr as usize)
@@ -331,20 +293,9 @@ pub mod guard {
                 Some(stackaddr as usize + guardsize as usize)
             };
         }
-        assert_eq!(pthread_attr_destroy(&mut attr), 0);
+        assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
         ret
     }
-
-    #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
-    extern {
-        fn pthread_getattr_np(native: libc::pthread_t,
-                              attr: *mut libc::pthread_attr_t) -> libc::c_int;
-        fn pthread_attr_getguardsize(attr: *const libc::pthread_attr_t,
-                                     guardsize: *mut libc::size_t) -> libc::c_int;
-        fn pthread_attr_getstack(attr: *const libc::pthread_attr_t,
-                                 stackaddr: *mut *mut libc::c_void,
-                                 stacksize: *mut libc::size_t) -> libc::c_int;
-    }
 }
 
 // glibc >= 2.15 has a __pthread_get_minstack() function that returns
@@ -394,21 +345,3 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize {
 fn min_stack_size(_: *const libc::pthread_attr_t) -> usize {
     PTHREAD_STACK_MIN as usize
 }
-
-extern {
-    fn pthread_self() -> libc::pthread_t;
-    fn pthread_create(native: *mut libc::pthread_t,
-                      attr: *const libc::pthread_attr_t,
-                      f: extern fn(*mut libc::c_void) -> *mut libc::c_void,
-                      value: *mut libc::c_void) -> libc::c_int;
-    fn pthread_join(native: libc::pthread_t,
-                    value: *mut *mut libc::c_void) -> libc::c_int;
-    fn pthread_attr_init(attr: *mut libc::pthread_attr_t) -> libc::c_int;
-    fn pthread_attr_destroy(attr: *mut libc::pthread_attr_t) -> libc::c_int;
-    fn pthread_attr_setstacksize(attr: *mut libc::pthread_attr_t,
-                                 stack_size: libc::size_t) -> libc::c_int;
-    fn pthread_attr_setdetachstate(attr: *mut libc::pthread_attr_t,
-                                   state: libc::c_int) -> libc::c_int;
-    fn pthread_detach(thread: libc::pthread_t) -> libc::c_int;
-    fn sched_yield() -> libc::c_int;
-}
diff --git a/src/libstd/sys/unix/thread_local.rs b/src/libstd/sys/unix/thread_local.rs
index e9bf214e816..d22118d4d79 100644
--- a/src/libstd/sys/unix/thread_local.rs
+++ b/src/libstd/sys/unix/thread_local.rs
@@ -8,62 +8,33 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![allow(dead_code)] // sys isn't exported yet
+#![allow(dead_code)] // not used on all platforms
 
-use libc::c_int;
+use mem;
+use libc;
 
-pub type Key = pthread_key_t;
+pub type Key = libc::pthread_key_t;
 
 #[inline]
 pub unsafe fn create(dtor: Option<unsafe extern fn(*mut u8)>) -> Key {
     let mut key = 0;
-    assert_eq!(pthread_key_create(&mut key, dtor), 0);
+    assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0);
     key
 }
 
 #[inline]
 pub unsafe fn set(key: Key, value: *mut u8) {
-    let r = pthread_setspecific(key, value);
+    let r = libc::pthread_setspecific(key, value as *mut _);
     debug_assert_eq!(r, 0);
 }
 
 #[inline]
 pub unsafe fn get(key: Key) -> *mut u8 {
-    pthread_getspecific(key)
+    libc::pthread_getspecific(key) as *mut u8
 }
 
 #[inline]
 pub unsafe fn destroy(key: Key) {
-    let r = pthread_key_delete(key);
+    let r = libc::pthread_key_delete(key);
     debug_assert_eq!(r, 0);
 }
-
-#[cfg(any(target_os = "macos",
-          target_os = "ios"))]
-type pthread_key_t = ::libc::c_ulong;
-
-#[cfg(any(target_os = "freebsd",
-          target_os = "dragonfly",
-          target_os = "bitrig",
-          target_os = "netbsd",
-          target_os = "openbsd",
-          target_os = "nacl"))]
-type pthread_key_t = ::libc::c_int;
-
-#[cfg(not(any(target_os = "macos",
-              target_os = "ios",
-              target_os = "freebsd",
-              target_os = "dragonfly",
-              target_os = "bitrig",
-              target_os = "netbsd",
-              target_os = "openbsd",
-              target_os = "nacl")))]
-type pthread_key_t = ::libc::c_uint;
-
-extern {
-    fn pthread_key_create(key: *mut pthread_key_t,
-                          dtor: Option<unsafe extern fn(*mut u8)>) -> c_int;
-    fn pthread_key_delete(key: pthread_key_t) -> c_int;
-    fn pthread_getspecific(key: pthread_key_t) -> *mut u8;
-    fn pthread_setspecific(key: pthread_key_t, value: *mut u8) -> c_int;
-}
diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs
index 35d55902f9c..5192f01269d 100644
--- a/src/libstd/sys/unix/time.rs
+++ b/src/libstd/sys/unix/time.rs
@@ -24,15 +24,10 @@ mod inner {
         t: u64
     }
 
-    extern {
-        pub fn mach_absolute_time() -> u64;
-        pub fn mach_timebase_info(info: *mut libc::mach_timebase_info) -> libc::c_int;
-    }
-
     impl SteadyTime {
         pub fn now() -> SteadyTime {
             SteadyTime {
-                t: unsafe { mach_absolute_time() },
+                t: unsafe { libc::mach_absolute_time() },
             }
         }
     }
@@ -46,7 +41,7 @@ mod inner {
 
         unsafe {
             ONCE.call_once(|| {
-                mach_timebase_info(&mut INFO);
+                libc::mach_timebase_info(&mut INFO);
             });
             &INFO
         }
@@ -87,11 +82,6 @@ mod inner {
     #[link(name = "rt")]
     extern {}
 
-    extern {
-        #[cfg_attr(target_os = "netbsd", link_name = "__clock_gettime50")]
-        fn clock_gettime(clk_id: libc::c_int, tp: *mut libc::timespec) -> libc::c_int;
-    }
-
     impl SteadyTime {
         pub fn now() -> SteadyTime {
             let mut t = SteadyTime {
@@ -101,7 +91,8 @@ mod inner {
                 }
             };
             unsafe {
-                assert_eq!(0, clock_gettime(libc::CLOCK_MONOTONIC, &mut t.t));
+                assert_eq!(0, libc::clock_gettime(libc::CLOCK_MONOTONIC,
+                                                  &mut t.t));
             }
             t
         }