diff --git a/base64/base64.rs b/base64/base64.rs index 7b0e23e8e..ca30682c1 100644 --- a/base64/base64.rs +++ b/base64/base64.rs @@ -11,8 +11,8 @@ #[feature(macro_rules)]; -extern mod serialize; -extern mod getopts; +extern crate serialize; +extern crate getopts; use std::char; use std::io::{println, File, stdin, stdout}; diff --git a/basename/basename.rs b/basename/basename.rs index 88839a98c..7ac29c5b5 100644 --- a/basename/basename.rs +++ b/basename/basename.rs @@ -10,8 +10,8 @@ * file that was distributed with this source code. */ -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::io::{print, println}; use std::os; diff --git a/cat/cat.rs b/cat/cat.rs index 4e5b937a0..929ae23ec 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -12,8 +12,8 @@ /* last synced with: cat (GNU coreutils) 8.13 */ -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::{print, stdin, stdout, File}; diff --git a/dirname/dirname.rs b/dirname/dirname.rs index 1fe84fb97..47af881fb 100644 --- a/dirname/dirname.rs +++ b/dirname/dirname.rs @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::print; diff --git a/echo/echo.rs b/echo/echo.rs index b680fbf93..0780b8cac 100644 --- a/echo/echo.rs +++ b/echo/echo.rs @@ -10,8 +10,8 @@ * file that was distributed with this source code. */ -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::{print, println}; diff --git a/hostname/hostname.rs b/hostname/hostname.rs index 3e7d64213..b0dae0a71 100644 --- a/hostname/hostname.rs +++ b/hostname/hostname.rs @@ -12,8 +12,8 @@ * https://www.opensource.apple.com/source/shell_cmds/shell_cmds-170/hostname/hostname.c?txt */ -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::{os,libc,vec,str}; use getopts::{optflag, getopts, usage}; diff --git a/id/id.rs b/id/id.rs index c5a017cc4..dff5b3ca2 100644 --- a/id/id.rs +++ b/id/id.rs @@ -13,13 +13,12 @@ * http://www.opensource.apple.com/source/shell_cmds/shell_cmds-118/id/id.c */ -extern mod getopts; +extern crate getopts; use std::{libc, os, vec}; -use std::ptr::{read_ptr, is_null, is_not_null}; -use std::libc::{c_char, c_int, time_t, uid_t, pid_t, c_uint, dev_t, c_float, getgid, getegid, getuid, getlogin}; +use std::ptr::read; +use std::libc::{c_char, c_int, time_t, uid_t, getgid, getegid, getuid, getlogin}; use std::str::raw::from_c_str; -use std::unstable::intrinsics::uninit; use getopts::{getopts, optflag, usage}; // These could be extracted into their own file @@ -40,36 +39,45 @@ struct c_group { gr_name: *c_char /* group name */ } -type au_id_t = uid_t; -type au_asid_t = pid_t; -type au_event_t = c_uint; -type au_emod_t = c_uint; -type au_class_t = c_int; +#[cfg(not(target_os = "linux"))] +mod audit { + pub use std::unstable::intrinsic::uninit; + use std::libc::{pid_t, c_uint, uint64_t, dev_t}; -struct au_mask { - am_success: c_uint, - am_failure: c_uint -} -type au_mask_t = au_mask; + type au_id_t = uid_t; + type au_asid_t = pid_t; + type au_event_t = c_uint; + type au_emod_t = c_uint; + type au_class_t = c_int; -struct au_tid_addr { - port: dev_t, -} -type au_tid_addr_t = au_tid_addr; + struct au_mask { + am_success: c_uint, + am_failure: c_uint + } + type au_mask_t = au_mask; -struct c_auditinfo_addr { - ai_auid: au_id_t, /* Audit user ID */ - ai_mask: au_mask_t, /* Audit masks. */ - ai_termid: au_tid_addr_t, /* Terminal ID. */ - ai_flags: c_float, /* Audit session flags */ - ai_asid: au_asid_t /* Audit session ID. */ + struct au_tid_addr { + port: dev_t, + } + type au_tid_addr_t = au_tid_addr; + + struct c_auditinfo_addr { + ai_auid: au_id_t, /* Audit user ID */ + ai_mask: au_mask_t, /* Audit masks. */ + ai_termid: au_tid_addr_t, /* Terminal ID. */ + ai_asid: au_asid_t, /* Audit session ID. */ + ai_flags: uint64_t /* Audit session flags */ + } + pub type c_auditinfo_addr_t = c_auditinfo_addr; + + extern { + pub fn getaudit(auditinfo_addr: *c_auditinfo_addr_t) -> c_int; + } } -type c_auditinfo_addr_t = c_auditinfo_addr; extern { fn getpwuid(uid: uid_t) -> *c_passwd; fn getgrgid(gid: uid_t) -> *c_group; - fn getaudit(auditinfo_addr: *c_auditinfo_addr_t) -> c_int; fn getpwnam(login: *c_char) -> *c_passwd; fn getgrouplist(name: *c_char, basegid: c_int, @@ -85,7 +93,7 @@ fn main () { let options = [ optflag("h", "", "Show help"), - optflag("A", "", "Display the process audit"), + optflag("A", "", "Display the process audit (not available on Linux)"), optflag("G", "", "Display the different group IDs"), optflag("g", "", "Display the effective group ID as a number"), optflag("n", "", "Display the name of the user or group ID for the -G, -g and -u options"), @@ -122,8 +130,8 @@ fn main () { let id = from_str::(username).unwrap(); let pw_pointer = unsafe { getpwuid(id) }; - if is_not_null(pw_pointer) { - Some(unsafe { read_ptr(pw_pointer) }) + if pw_pointer.is_not_null() { + Some(unsafe { read(pw_pointer) }) } else { no_such_user(username); return; @@ -134,8 +142,8 @@ fn main () { let pw_pointer = unsafe { getpwnam(username.as_slice().as_ptr() as *i8) }; - if is_not_null(pw_pointer) { - Some(unsafe { read_ptr(pw_pointer) }) + if pw_pointer.is_not_null() { + Some(unsafe { read(pw_pointer) }) } else { no_such_user(username); return; @@ -163,8 +171,8 @@ fn main () { } as u32; let gr = unsafe { getgrgid(id) }; - if nflag && is_not_null(gr) { - let gr_name = unsafe { from_c_str(read_ptr(gr).gr_name) }; + if nflag && gr.is_not_null() { + let gr_name = unsafe { from_c_str(read(gr).gr_name) }; println!("{:s}", gr_name); } else { println!("{:u}", id); @@ -182,13 +190,13 @@ fn main () { }; let pw = unsafe { getpwuid(id as u32) }; - if nflag && is_not_null(pw) { + if nflag && pw.is_not_null() { let pw_name = unsafe { - from_c_str(read_ptr(pw).pw_name) + from_c_str(read(pw).pw_name) }; println!("{:s}", pw_name); } else { - println!("{:d}", id); + println!("{:d}", id); } return; @@ -229,28 +237,28 @@ fn pretty(possible_pw: Option) { let pw = unsafe { getpwuid(rid) }; let is_same_user = unsafe { - from_c_str(read_ptr(pw).pw_name) == login + from_c_str(read(pw).pw_name) == login }; - if is_null(pw) || is_same_user { + if pw.is_null() || is_same_user { println!("login\t{:s}", login); } - if is_not_null(pw) { + if pw.is_not_null() { println!( "uid\t{:s}", - unsafe { from_c_str(read_ptr(pw).pw_name) }) + unsafe { from_c_str(read(pw).pw_name) }) } else { - println!("uid\t{:u}\n", rid); + println!("uid\t{:u}\n", rid); } let eid = unsafe { getegid() }; if eid == rid { let pw = unsafe { getpwuid(eid) }; - if is_not_null(pw) { + if pw.is_not_null() { println!( "euid\t{:s}", - unsafe { from_c_str(read_ptr(pw).pw_name) }); + unsafe { from_c_str(read(pw).pw_name) }); } else { println!("euid\t{:u}", eid); } @@ -260,10 +268,10 @@ fn pretty(possible_pw: Option) { if rid != eid { let gr = unsafe { getgrgid(rid) }; - if is_not_null(gr) { + if gr.is_not_null() { println!( "rgid\t{:s}", - unsafe { from_c_str(read_ptr(gr).gr_name) }); + unsafe { from_c_str(read(gr).gr_name) }); } else { println!("rgid\t{:u}", rid); } @@ -276,7 +284,7 @@ fn pretty(possible_pw: Option) { fn pline(possible_pw: Option) { let pw = if possible_pw.is_none() { - unsafe { read_ptr(getpwuid(getuid())) } + unsafe { read(getpwuid(getuid())) } } else { possible_pw.unwrap() }; @@ -333,9 +341,9 @@ fn group(possible_pw: Option, nflag: bool) { for &g in groups.iter() { if nflag { let group = unsafe { getgrgid(g as u32) }; - if is_not_null(group) { + if group.is_not_null() { let name = unsafe { - from_c_str(read_ptr(group).gr_name) + from_c_str(read(group).gr_name) }; print!("{:s} ", name); } @@ -347,10 +355,14 @@ fn group(possible_pw: Option, nflag: bool) { println!(""); } -fn auditid () { - let auditinfo: c_auditinfo_addr_t = unsafe { uninit() }; - let address = &auditinfo as *c_auditinfo_addr_t; - if unsafe { getaudit(address) } < 0 { +#[cfg(target_os = "linux")] +fn auditid() { } + +#[cfg(not(target_os = "linux"))] +fn auditid() { + let auditinfo: audit::c_auditinfo_addr_t = unsafe { audit::uninit() }; + let address = &auditinfo as *audit::c_auditinfo_addr_t; + if unsafe { audit::getaudit(address) } < 0 { println!("Couldlnt retrieve information"); return; } @@ -403,20 +415,20 @@ fn id_print(possible_pw: Option, print!(" gid={:d}", gid); let gr = unsafe { getgrgid(gid as u32) }; - if is_not_null(gr) { + if gr.is_not_null() { print!( "({:s})", - unsafe { from_c_str(read_ptr(gr).gr_name) }); + unsafe { from_c_str(read(gr).gr_name) }); } let euid = unsafe { libc::geteuid() }; if p_euid && (euid != uid as u32) { print!(" euid={:u}", euid); let pw = unsafe { getpwuid(euid) }; - if is_not_null(pw) { + if pw.is_not_null() { print!( "({:s})", - unsafe { from_c_str(read_ptr(pw).pw_name) }); + unsafe { from_c_str(read(pw).pw_name) }); } } @@ -425,8 +437,8 @@ fn id_print(possible_pw: Option, print!(" egid={:u}", egid); unsafe { let grp = getgrgid(egid); - if is_not_null(grp) { - print!("({:s})", from_c_str(read_ptr(grp).gr_name)); + if grp.is_not_null() { + print!("({:s})", from_c_str(read(grp).gr_name)); } } } @@ -441,9 +453,9 @@ fn id_print(possible_pw: Option, if !first { print!(",") } print!("{:d}", gr); let group = unsafe { getgrgid(gr as u32) }; - if is_not_null(group) { + if group.is_not_null() { let name = unsafe { - from_c_str(read_ptr(group).gr_name) + from_c_str(read(group).gr_name) }; print!("({:s})", name); } diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index f6084dd3b..4cf6c78cc 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -11,8 +11,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::fs; diff --git a/printenv/printenv.rs b/printenv/printenv.rs index 2db559d8e..bee1f8d0f 100644 --- a/printenv/printenv.rs +++ b/printenv/printenv.rs @@ -13,8 +13,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::print; diff --git a/pwd/pwd.rs b/pwd/pwd.rs index 5f29d81bd..be638c817 100644 --- a/pwd/pwd.rs +++ b/pwd/pwd.rs @@ -11,8 +11,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::print; diff --git a/rm/rm.rs b/rm/rm.rs index f9056cfc3..00809d3b3 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -11,8 +11,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::{print, stdin, stdio, fs, BufferedReader}; diff --git a/rmdir/rmdir.rs b/rmdir/rmdir.rs index 86121cdb8..6b344325e 100644 --- a/rmdir/rmdir.rs +++ b/rmdir/rmdir.rs @@ -11,8 +11,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::{print, fs}; diff --git a/seq/seq.rs b/seq/seq.rs index c9ea54a43..baee8d492 100644 --- a/seq/seq.rs +++ b/seq/seq.rs @@ -5,8 +5,8 @@ // TODO: Make -w flag work with decimals // TODO: Support -f flag -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::cmp::max; diff --git a/sleep/sleep.rs b/sleep/sleep.rs index b0318b780..5475b4b01 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -11,8 +11,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::num; use std::cast; diff --git a/tee/tee.rs b/tee/tee.rs index 72b9427f7..86db68d2a 100644 --- a/tee/tee.rs +++ b/tee/tee.rs @@ -10,8 +10,8 @@ * file that was distributed with this source code. */ -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::io::{println, stdin, stdout, Append, File, Truncate, Write}; use std::io::{IoResult}; diff --git a/truncate/truncate.rs b/truncate/truncate.rs index f1d215267..092efc5b6 100644 --- a/truncate/truncate.rs +++ b/truncate/truncate.rs @@ -11,8 +11,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::io::{File, Open, ReadWrite, fs}; use std::os; @@ -108,7 +108,7 @@ file based on its current size: } } -fn truncate(no_create: bool, io_blocks: bool, reference: Option<~str>, size: Option<~str>, filenames: ~[~str]) { +fn truncate(no_create: bool, _: bool, reference: Option<~str>, size: Option<~str>, filenames: ~[~str]) { let (refsize, mode) = match reference { Some(rfilename) => { let rfile = match File::open(&Path::new(rfilename.clone())) { diff --git a/tty/tty.rs b/tty/tty.rs index 883d73448..b416fecc4 100644 --- a/tty/tty.rs +++ b/tty/tty.rs @@ -16,8 +16,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::{libc,str,os}; use std::io::println; diff --git a/users/users.rs b/users/users.rs index e4d752e11..00c82a7d7 100644 --- a/users/users.rs +++ b/users/users.rs @@ -16,8 +16,8 @@ #[feature(macro_rules, globs)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::io::print; use std::cast; diff --git a/wc/wc.rs b/wc/wc.rs index f53ce4334..64122e5e5 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -11,8 +11,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::str::from_utf8; diff --git a/whoami/whoami.rs b/whoami/whoami.rs index dc393ad77..9369cbf0c 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -13,8 +13,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::io::print; use std::os; diff --git a/yes/yes.rs b/yes/yes.rs index 0a2c84db9..8543f20f6 100644 --- a/yes/yes.rs +++ b/yes/yes.rs @@ -13,8 +13,8 @@ #[feature(macro_rules)]; -extern mod extra; -extern mod getopts; +extern crate extra; +extern crate getopts; use std::os; use std::io::{print, println};