From b6018f38e8306b7fc6e16d89e83c7a8aa64219d9 Mon Sep 17 00:00:00 2001 From: Alan Andrade Date: Sun, 23 Feb 2014 21:55:01 -0800 Subject: [PATCH] whoami and id use c_types --- common/c_types.rs | 24 ++++++++++++++++++++++++ id/id.rs | 27 ++++++--------------------- whoami/whoami.rs | 10 +++------- 3 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 common/c_types.rs diff --git a/common/c_types.rs b/common/c_types.rs new file mode 100644 index 000000000..6994e24e4 --- /dev/null +++ b/common/c_types.rs @@ -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 */ +} diff --git a/id/id.rs b/id/id.rs index 7970fe2aa..3a52c6d35 100644 --- a/id/id.rs +++ b/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 { diff --git a/whoami/whoami.rs b/whoami/whoami.rs index d632cf11c..3487f31e1 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -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;