Rollup merge of #64640 - Wind-River:master, r=alexcrichton
No home directory on vxWorks r? @alexcrichton
This commit is contained in:
commit
6254d7a80a
@ -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 })
|
||||
}
|
||||
|
@ -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) -> ! {
|
||||
|
Loading…
Reference in New Issue
Block a user