diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index bbc4be9c68a..5ee44bbfece 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; use io::prelude::*; use os::unix::prelude::*; @@ -23,11 +24,6 @@ use sys::fd::FileDesc; use sys::platform::raw; use sys::{cvt, cvt_r}; use sys_common::{AsInner, FromInner}; -use vec::Vec; -#[cfg(target_os = "solaris")] -use core_collections::borrow::ToOwned; -#[cfg(target_os = "solaris")] -use boxed::Box; pub struct File(FileDesc); diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index fc1fea4bc71..da770514593 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -507,28 +507,6 @@ pub fn home_dir() -> Option { fallback() }).map(PathBuf::from); - #[cfg(not(target_os = "solaris"))] - unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, - buf: &mut Vec) -> Option<()> { - let mut result = ptr::null_mut(); - match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), - buf.capacity() as libc::size_t, - &mut result) { - 0 if !result.is_null() => Some(()), - _ => None - } - } - - #[cfg(target_os = "solaris")] - unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, - buf: &mut Vec) -> Option<()> { - // getpwuid_r semantics is different on Illumos/Solaris: - // http://illumos.org/man/3c/getpwuid_r - let result = libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), - buf.capacity() as libc::size_t); - if result.is_null() { None } else { Some(()) } - } - #[cfg(any(target_os = "android", target_os = "ios", target_os = "nacl"))] @@ -537,6 +515,28 @@ pub fn home_dir() -> Option { target_os = "ios", target_os = "nacl")))] unsafe fn fallback() -> Option { + #[cfg(not(target_os = "solaris"))] + unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, + buf: &mut Vec) -> Option<()> { + let mut result = ptr::null_mut(); + match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), + buf.capacity() as libc::size_t, + &mut result) { + 0 if !result.is_null() => Some(()), + _ => None + } + } + + #[cfg(target_os = "solaris")] + unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, + buf: &mut Vec) -> Option<()> { + // getpwuid_r semantics is different on Illumos/Solaris: + // http://illumos.org/man/3c/getpwuid_r + let result = libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), + buf.capacity() as libc::size_t); + if result.is_null() { None } else { Some(()) } + } + let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, n => n as usize,