From dca986f599e1abe4270a06efaf91759a926f2424 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sun, 29 Jan 2023 17:23:14 +0000 Subject: Remove users dependency --- src/passwd.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/passwd.rs (limited to 'src/passwd.rs') diff --git a/src/passwd.rs b/src/passwd.rs new file mode 100644 index 0000000..40ec947 --- /dev/null +++ b/src/passwd.rs @@ -0,0 +1,11 @@ +use libc::uid_t; +use std::ffi::CStr; + +pub fn get_uid_by_name + ?Sized>(name: &S) -> Option { + let passwd = unsafe { libc::getpwnam(name.as_ref().as_ptr()) }; + if !passwd.is_null() { + Some(unsafe { *passwd }.pw_uid) + } else { + None + } +} -- cgit v1.2.3-54-g00ecf