1 2 3 4 5 6 7 8 9 10 11
use libc::uid_t; use std::ffi::CStr; pub fn get_uid_by_name<S: AsRef<CStr> + ?Sized>(name: &S) -> Option<uid_t> { let passwd = unsafe { libc::getpwnam(name.as_ref().as_ptr()) }; if !passwd.is_null() { Some(unsafe { *passwd }.pw_uid) } else { None } }