logname: reduce range of unsafe block

This commit is contained in:
oech3
2026-03-26 20:03:31 +09:00
committed by Daniel Hofstetter
parent 37d07e455b
commit 230e0cfd65
+5 -7
View File
@@ -12,13 +12,11 @@ use uucore::translate;
use uucore::{error::UResult, show_error};
fn get_userlogin() -> Option<String> {
unsafe {
let login: *const libc::c_char = libc::getlogin();
if login.is_null() {
None
} else {
Some(String::from_utf8_lossy(CStr::from_ptr(login).to_bytes()).to_string())
}
let login_ptr = unsafe { libc::getlogin() };
if login_ptr.is_null() {
None
} else {
Some(String::from_utf8_lossy(unsafe { CStr::from_ptr(login_ptr) }.to_bytes()).to_string())
}
}