You've already forked rust-users
mirror of
https://github.com/uutils/rust-users.git
synced 2026-06-10 15:48:37 -07:00
Merge branch 'all-users' of https://github.com/polachok/rust-users into polachok-all-users
# Conflicts: # src/lib.rs I put the users iterator functionality into the 'base' module, where it belongs now (but didn't when the code was written)
This commit is contained in:
+29
@@ -90,6 +90,10 @@ extern {
|
||||
|
||||
fn getgid() -> gid_t;
|
||||
fn getegid() -> gid_t;
|
||||
|
||||
fn setpwent();
|
||||
fn getpwent() -> *const c_passwd;
|
||||
fn endpwent();
|
||||
}
|
||||
|
||||
|
||||
@@ -385,6 +389,31 @@ pub fn get_effective_groupname() -> Option<String> {
|
||||
}
|
||||
|
||||
|
||||
pub struct AllUsers(());
|
||||
|
||||
impl AllUsers {
|
||||
pub unsafe fn new() -> AllUsers {
|
||||
unsafe { setpwent() };
|
||||
AllUsers(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for AllUsers {
|
||||
fn drop(&mut self) {
|
||||
unsafe { endpwent() };
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for AllUsers {
|
||||
type Item = User;
|
||||
|
||||
fn next(&mut self) -> Option<User> {
|
||||
unsafe { passwd_to_user(getpwent()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// OS-specific extensions to users and groups.
|
||||
///
|
||||
/// Every OS has a different idea of what data a user or a group comes with.
|
||||
|
||||
@@ -120,6 +120,7 @@ pub use base::{get_current_uid, get_current_username};
|
||||
pub use base::{get_effective_uid, get_effective_username};
|
||||
pub use base::{get_current_gid, get_current_groupname};
|
||||
pub use base::{get_effective_gid, get_effective_groupname};
|
||||
pub use base::AllUsers;
|
||||
|
||||
|
||||
pub mod cache;
|
||||
|
||||
Reference in New Issue
Block a user