fix users

This commit is contained in:
kwantam 2015-04-27 17:38:39 -04:00
parent 09937b66b9
commit 143aea72ee

View file

@ -1,5 +1,5 @@
#![crate_name = "users"] #![crate_name = "users"]
#![feature(collections, core, old_io, rustc_private, std_misc)] #![feature(rustc_private)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
@ -13,13 +13,12 @@
/* last synced with: whoami (GNU coreutils) 8.22 */ /* last synced with: whoami (GNU coreutils) 8.22 */
// Allow dead code here in order to keep all fields, constants here, for consistency. // Allow dead code here in order to keep all fields, constants here, for consistency.
#![allow(dead_code, non_camel_case_types)] #![allow(dead_code)]
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::old_io::print;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use utmpx::*; use utmpx::*;
@ -53,13 +52,12 @@ unsafe extern fn utmpxname(_file: *const libc::c_char) -> libc::c_int {
static NAME: &'static str = "users"; static NAME: &'static str = "users";
pub fn uumain(args: Vec<String>) -> i32 { pub fn uumain(args: Vec<String>) -> i32 {
let program = args[0].as_slice();
let opts = [ let opts = [
getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"), getopts::optflag("V", "version", "output version information and exit"),
]; ];
let matches = match getopts::getopts(args.tail(), &opts) { let matches = match getopts::getopts(&args[1..], &opts) {
Ok(m) => m, Ok(m) => m,
Err(f) => panic!("{}", f), Err(f) => panic!("{}", f),
}; };
@ -68,9 +66,9 @@ pub fn uumain(args: Vec<String>) -> i32 {
println!("users 1.0.0"); println!("users 1.0.0");
println!(""); println!("");
println!("Usage:"); println!("Usage:");
println!(" {} [OPTION]... [FILE]", program); println!(" {} [OPTION]... [FILE]", args[0]);
println!(""); println!("");
print(getopts::usage("Output who is currently logged in according to FILE.", &opts).as_slice()); println!("{}", getopts::usage("Output who is currently logged in according to FILE.", &opts));
return 0; return 0;
} }
@ -79,10 +77,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
return 0; return 0;
} }
let mut filename = DEFAULT_FILE; let filename = if matches.free.len() > 0 {
if matches.free.len() > 0 { matches.free[0].as_ref()
filename = matches.free[0].as_slice(); } else {
} DEFAULT_FILE
};
exec(filename); exec(filename);