Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 7c53ecd

Browse files
xen0nsoc
authored andcommitted
Rustfmt
1 parent 88294e4 commit 7c53ecd

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ pub fn video_dir() -> Option<PathBuf> {
254254
sys::video_dir()
255255
}
256256

257-
258257
#[cfg(test)]
259258
mod tests {
260259
#[test]

src/unix.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
#![cfg(unix)]
22

33
use std::env;
4-
use std::path::PathBuf;
5-
use std::mem;
6-
use std::ptr;
74
use std::ffi::CStr;
85
use std::ffi::OsString;
6+
use std::mem;
97
use std::os::unix::ffi::OsStringExt;
8+
use std::path::PathBuf;
9+
use std::ptr;
1010

1111
extern crate libc;
1212

1313
// https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/os.rs#L498
1414
pub fn home_dir() -> Option<PathBuf> {
15-
return env::var_os("HOME").and_then(|h| { if h.is_empty() { None } else { Some(h) } } ).or_else(|| unsafe {
16-
fallback()
17-
}).map(PathBuf::from);
15+
return env::var_os("HOME")
16+
.and_then(|h| if h.is_empty() { None } else { Some(h) })
17+
.or_else(|| unsafe { fallback() })
18+
.map(PathBuf::from);
1819

19-
#[cfg(any(target_os = "android",
20-
target_os = "ios",
21-
target_os = "emscripten"))]
22-
unsafe fn fallback() -> Option<OsString> { None }
23-
#[cfg(not(any(target_os = "android",
24-
target_os = "ios",
25-
target_os = "emscripten")))]
20+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "emscripten"))]
21+
unsafe fn fallback() -> Option<OsString> {
22+
None
23+
}
24+
#[cfg(not(any(target_os = "android", target_os = "ios", target_os = "emscripten")))]
2625
unsafe fn fallback() -> Option<OsString> {
2726
let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {
2827
n if n < 0 => 512 as usize,
@@ -31,8 +30,13 @@ pub fn home_dir() -> Option<PathBuf> {
3130
let mut buf = Vec::with_capacity(amt);
3231
let mut passwd: libc::passwd = mem::zeroed();
3332
let mut result = ptr::null_mut();
34-
match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(),
35-
buf.capacity(), &mut result) {
33+
match libc::getpwuid_r(
34+
libc::getuid(),
35+
&mut passwd,
36+
buf.as_mut_ptr(),
37+
buf.capacity(),
38+
&mut result,
39+
) {
3640
0 if !result.is_null() => {
3741
let ptr = passwd.pw_dir as *const _;
3842
let bytes = CStr::from_ptr(ptr).to_bytes();
@@ -41,9 +45,8 @@ pub fn home_dir() -> Option<PathBuf> {
4145
} else {
4246
Some(OsStringExt::from_vec(bytes.to_vec()))
4347
}
44-
},
48+
}
4549
_ => None,
4650
}
4751
}
4852
}
49-

0 commit comments

Comments
 (0)