Rollup merge of #64640 - Wind-River:master, r=alexcrichton

No home directory on vxWorks

r? @alexcrichton
This commit is contained in:
Mazdak Farrokhzad 2019-09-21 16:01:32 +02:00 committed by GitHub
commit 6254d7a80a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 23 deletions

View File

@ -529,7 +529,7 @@ pub fn stat(p: &Path) -> io::Result<FileAttr> {
let p = cstr(p)?;
let mut stat: stat64 = unsafe { mem::zeroed() };
cvt(unsafe {
libc::lstat(p.as_ptr(), &mut stat as *mut _ as *mut _)
libc::stat(p.as_ptr(), &mut stat as *mut _ as *mut _)
})?;
Ok(FileAttr { stat })
}

View File

@ -287,28 +287,7 @@ pub fn temp_dir() -> PathBuf {
}
pub fn home_dir() -> Option<PathBuf> {
return crate::env::var_os("HOME").or_else(|| unsafe {
fallback()
}).map(PathBuf::from);
unsafe fn fallback() -> Option<OsString> {
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();
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,
}
}
None
}
pub fn exit(code: i32) -> ! {