mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
commit
a6f9d806e6
2 changed files with 39 additions and 1 deletions
|
@ -6,8 +6,8 @@ use self::libc::{
|
|||
c_char,
|
||||
c_int,
|
||||
uid_t,
|
||||
time_t
|
||||
};
|
||||
#[cfg(target_os = "macos")] use self::libc::time_t;
|
||||
use self::libc::funcs::posix88::unistd::getgroups;
|
||||
|
||||
use std::vec::Vec;
|
||||
|
@ -15,6 +15,7 @@ use std::vec::Vec;
|
|||
use std::ptr::read;
|
||||
use std::str::raw::from_c_str;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub struct c_passwd {
|
||||
pub pw_name: *c_char, /* user name */
|
||||
pub pw_passwd: *c_char, /* user name */
|
||||
|
@ -28,6 +29,17 @@ pub struct c_passwd {
|
|||
pub pw_expire: time_t
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub struct c_passwd {
|
||||
pub pw_name: *c_char, /* user name */
|
||||
pub pw_passwd: *c_char, /* user name */
|
||||
pub pw_uid: c_int, /* user uid */
|
||||
pub pw_gid: c_int, /* user gid */
|
||||
pub pw_gecos: *c_char,
|
||||
pub pw_dir: *c_char,
|
||||
pub pw_shell: *c_char,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub struct utsname {
|
||||
pub sysname: [c_char, ..256],
|
||||
|
|
26
id/id.rs
26
id/id.rs
|
@ -256,6 +256,7 @@ fn pretty(possible_pw: Option<c_passwd>) {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn pline(possible_pw: Option<c_passwd>) {
|
||||
let pw = if possible_pw.is_none() {
|
||||
unsafe { read(getpwuid(getuid() as i32)) }
|
||||
|
@ -284,6 +285,31 @@ fn pline(possible_pw: Option<c_passwd>) {
|
|||
pw_shell);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn pline(possible_pw: Option<c_passwd>) {
|
||||
let pw = if possible_pw.is_none() {
|
||||
unsafe { read(getpwuid(getuid() as i32)) }
|
||||
} else {
|
||||
possible_pw.unwrap()
|
||||
};
|
||||
|
||||
let pw_name = unsafe { from_c_str(pw.pw_name) };
|
||||
let pw_passwd = unsafe { from_c_str(pw.pw_passwd)};
|
||||
let pw_gecos = unsafe { from_c_str(pw.pw_gecos) };
|
||||
let pw_dir = unsafe { from_c_str(pw.pw_dir) };
|
||||
let pw_shell = unsafe { from_c_str(pw.pw_shell) };
|
||||
|
||||
println!(
|
||||
"{:s}:{:s}:{:d}:{:d}:{:s}:{:s}:{:s}",
|
||||
pw_name,
|
||||
pw_passwd,
|
||||
pw.pw_uid,
|
||||
pw.pw_gid,
|
||||
pw_gecos,
|
||||
pw_dir,
|
||||
pw_shell);
|
||||
}
|
||||
|
||||
static NGROUPS: i32 = 20;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue