Skip to content

Commit

Permalink
Merge pull request rust-lang#24 from Wind-River/home_directory
Browse files Browse the repository at this point in the history
No home directory on vxWorks
  • Loading branch information
n-salim committed Sep 20, 2019
2 parents 66b1649 + 491a0c6 commit fbf9fa4
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions src/libstd/sys/vxworks/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> ! {
Expand Down

0 comments on commit fbf9fa4

Please sign in to comment.