diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-07-30 17:56:50 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-07-30 17:56:50 +0300 |
commit | 4f5bcfd1d4681356cb5223f1bdf93e2c632b19e3 (patch) | |
tree | 53339b83c8cb87a3ed750c4b513b23709f196ec4 /ui | |
parent | 69927f524c68f913b64391377b4cb252902b696a (diff) |
fix compilation error on bsds
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/lib.rs | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 6650112c..443d4932 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -78,29 +78,65 @@ pub mod username { use std::ptr::null_mut; /* taken from whoami-0.1.1 */ fn getpwuid() -> libc::passwd { - let mut pwent = libc::passwd { - pw_name: null_mut(), - pw_passwd: null_mut(), - pw_uid: 0, - pw_gid: 0, - pw_gecos: null_mut(), - pw_dir: null_mut(), - pw_shell: null_mut(), - }; let mut pwentp = null_mut(); let mut buffer = [0i8; 16384]; // from the man page - - unsafe { - libc::getpwuid_r( - libc::geteuid(), - &mut pwent, - &mut buffer[0], - 16384, - &mut pwentp, - ); + #[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "dragonfly", + target_os = "openbsd", + target_os = "netbsd" + ))] + { + let mut pwent = libc::passwd { + pw_name: null_mut(), + pw_passwd: null_mut(), + pw_uid: 0, + pw_gid: 0, + pw_change: 0, + pw_class: null_mut(), + pw_gecos: null_mut(), + pw_dir: null_mut(), + pw_shell: null_mut(), + pw_expire: 0, + }; + unsafe { + libc::getpwuid_r( + libc::geteuid(), + &mut pwent, + &mut buffer[0], + 16384, + &mut pwentp, + ); + } + + pwent + } + #[cfg(target_os = "linux")] + { + let mut pwent = libc::passwd { + pw_name: null_mut(), + pw_passwd: null_mut(), + pw_uid: 0, + pw_gid: 0, + pw_gecos: null_mut(), + pw_dir: null_mut(), + pw_shell: null_mut(), + }; + + unsafe { + libc::getpwuid_r( + libc::geteuid(), + &mut pwent, + &mut buffer[0], + 16384, + &mut pwentp, + ); + } + + pwent } - - pwent } fn ptr_to_string(name: *mut i8) -> String { let uname = name as *mut _ as *mut u8; |