Mercurial > hg > Members > anatofuz > ie-virsh
view src/main.rs @ 2:1632a34a3f6c
fix function name
author | AnaTofuZ <anatofuz@gmail.com> |
---|---|
date | Thu, 22 Oct 2020 13:09:13 +0900 |
parents | dba3414e8f7e |
children | 5bdb02e05c86 |
line wrap: on
line source
use nix; fn main() { let uid = getuid(); let gid = getgid(); let login_user = getlogin(uid); println!("uid: {} gid: {} name: {}", uid, gid, login_user); } fn getlogin(uid: u32) -> &'static str { use std::ffi::CStr; let user_passwd = unsafe { nix::libc::getpwuid(uid)}; let c_str = unsafe { CStr::from_ptr((*user_passwd).pw_name)} ; return c_str.to_str().unwrap(); } fn getuid() -> u32 { let uid_struct = nix::unistd::getuid(); return uid_struct.as_raw(); } fn getgid() -> u32 { let gid_struct = nix::unistd::getgid(); return gid_struct.as_raw(); }