Skip to content

Commit

Permalink
Rollup merge of rust-lang#39871 - binarycrusader:issue-39868, r=alexc…
Browse files Browse the repository at this point in the history
…richton

libstd needs update for pending libc change

This  updates libstd to accommodate the fixes made in rust-lang/libc#523

Fixes rust-lang#39868
  • Loading branch information
GuillaumeGomez committed Feb 16, 2017
2 parents c2c1313 + 5789539 commit 892d896
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,41 +483,21 @@ pub fn home_dir() -> Option<PathBuf> {
target_os = "nacl",
target_os = "emscripten")))]
unsafe fn fallback() -> Option<OsString> {
#[cfg(not(target_os = "solaris"))]
unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd,
buf: &mut Vec<c_char>) -> Option<()> {
let mut result = ptr::null_mut();
match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(),
buf.capacity(),
&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<c_char>) -> 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());
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,
};
let mut buf = Vec::with_capacity(amt);
let mut passwd: libc::passwd = mem::zeroed();

if getpwduid_r(libc::getuid(), &mut passwd, &mut buf).is_some() {
let ptr = passwd.pw_dir as *const _;
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
Some(OsStringExt::from_vec(bytes))
} else {
None
let mut result = ptr::null_mut();
match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(),
buf.capacity(), &mut result) {
0 if !result.is_null() => {
let ptr = passwd.pw_dir as *const _;
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
Some(OsStringExt::from_vec(bytes))
},
_ => None,
}
}
}
Expand Down

0 comments on commit 892d896

Please sign in to comment.