mirror of
https://github.com/uutils/coreutils
synced 2024-11-15 01:17:09 +00:00
whoami and id use c_types
This commit is contained in:
parent
2420c38b7e
commit
b6018f38e8
3 changed files with 33 additions and 28 deletions
24
common/c_types.rs
Normal file
24
common/c_types.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
#[allow(dead_code)];
|
||||
|
||||
use std::libc::{
|
||||
c_char,
|
||||
c_int,
|
||||
time_t
|
||||
};
|
||||
|
||||
pub struct c_passwd {
|
||||
pw_name: *c_char, /* user name */
|
||||
pw_passwd: *c_char, /* user name */
|
||||
pw_uid: c_int, /* user uid */
|
||||
pw_gid: c_int, /* user gid */
|
||||
pw_change: time_t,
|
||||
pw_class: *c_char,
|
||||
pw_gecos: *c_char,
|
||||
pw_dir: *c_char,
|
||||
pw_shell: *c_char,
|
||||
pw_expire: time_t
|
||||
}
|
||||
|
||||
pub struct c_group {
|
||||
gr_name: *c_char /* group name */
|
||||
}
|
27
id/id.rs
27
id/id.rs
|
@ -22,7 +22,6 @@ use std::ptr::read;
|
|||
use std::libc::{
|
||||
c_char,
|
||||
c_int,
|
||||
time_t,
|
||||
uid_t,
|
||||
getgid,
|
||||
getegid,
|
||||
|
@ -31,27 +30,13 @@ use std::libc::{
|
|||
};
|
||||
use std::str::raw::from_c_str;
|
||||
use getopts::{getopts, optflag, usage};
|
||||
use c_types::{
|
||||
c_passwd,
|
||||
c_group
|
||||
};
|
||||
|
||||
#[path = "../common/util.rs"]
|
||||
mod util;
|
||||
|
||||
// These could be extracted into their own file
|
||||
struct c_passwd {
|
||||
pw_name: *c_char, /* user name */
|
||||
pw_passwd: *c_char, /* user name */
|
||||
pw_uid: c_int, /* user uid */
|
||||
pw_gid: c_int, /* user gid */
|
||||
pw_change: time_t,
|
||||
pw_class: *c_char,
|
||||
pw_gecos: *c_char,
|
||||
pw_dir: *c_char,
|
||||
pw_shell: *c_char,
|
||||
pw_expire: time_t
|
||||
}
|
||||
|
||||
struct c_group {
|
||||
gr_name: *c_char /* group name */
|
||||
}
|
||||
#[path = "../common/util.rs"] mod util;
|
||||
#[path = "../common/c_types.rs"] mod c_types;
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
mod audit {
|
||||
|
|
|
@ -22,14 +22,10 @@ use std::io::print;
|
|||
use std::os;
|
||||
use std::str;
|
||||
use std::libc;
|
||||
use c_types::c_passwd;
|
||||
|
||||
#[path = "../common/util.rs"]
|
||||
mod util;
|
||||
|
||||
struct c_passwd {
|
||||
pw_name: *libc::c_char,
|
||||
// Maybe I should put here others struct members, but...Well, maybe.
|
||||
}
|
||||
#[path = "../common/util.rs"] mod util;
|
||||
#[path = "../common/c_types.rs"] mod c_types;
|
||||
|
||||
extern {
|
||||
pub fn geteuid() -> libc::c_int;
|
||||
|
|
Loading…
Reference in a new issue