mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 21:17:46 +00:00
commit
0c89fcda25
1 changed files with 13 additions and 8 deletions
|
@ -28,10 +28,15 @@ extern {
|
||||||
pub fn getlogin() -> *const libc::c_char;
|
pub fn getlogin() -> *const libc::c_char;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn get_userlogin() -> String {
|
fn get_userlogin() -> Option<String> {
|
||||||
let login: *const libc::c_char = getlogin();
|
unsafe {
|
||||||
|
let login: *const libc::c_char = getlogin();
|
||||||
String::from_raw_buf(login as *const u8)
|
if login.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(String::from_raw_buf(login as *const u8))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static NAME: &'static str = "logname";
|
static NAME: &'static str = "logname";
|
||||||
|
@ -77,8 +82,8 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec() {
|
fn exec() {
|
||||||
unsafe {
|
match get_userlogin() {
|
||||||
let userlogin = get_userlogin();
|
Some(userlogin) => println!("{}", userlogin),
|
||||||
println!("{}", userlogin);
|
None => println!("{}: no login name", NAME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue