mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
Fix groups and logname.
Minor upgrades and whitespace corrections.
This commit is contained in:
parent
521166cff9
commit
c7d07315b8
2 changed files with 18 additions and 24 deletions
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "groups"]
|
#![crate_name = "groups"]
|
||||||
#![feature(collections, rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -12,12 +12,9 @@
|
||||||
*/
|
*/
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
use getopts::{
|
|
||||||
optflag,
|
|
||||||
getopts,
|
|
||||||
usage
|
|
||||||
};
|
|
||||||
use c_types::{get_pw_from_args, group};
|
use c_types::{get_pw_from_args, group};
|
||||||
|
use getopts::{getopts, optflag, usage};
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
#[path = "../common/util.rs"] #[macro_use] mod util;
|
#[path = "../common/util.rs"] #[macro_use] mod util;
|
||||||
#[path = "../common/c_types.rs"] mod c_types;
|
#[path = "../common/c_types.rs"] mod c_types;
|
||||||
|
@ -33,7 +30,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
optflag("V", "version", "display version information and exit")
|
optflag("V", "version", "display version information and exit")
|
||||||
];
|
];
|
||||||
|
|
||||||
let matches = match getopts(args.tail(), &options) {
|
let matches = match getopts(&args[1..], &options) {
|
||||||
Ok(m) => { m },
|
Ok(m) => { m },
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
show_error!("{}", f);
|
show_error!("{}", f);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "logname"]
|
#![crate_name = "logname"]
|
||||||
#![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.
|
||||||
|
@ -12,14 +12,11 @@
|
||||||
|
|
||||||
/* last synced with: logname (GNU coreutils) 8.22 */
|
/* last synced with: logname (GNU coreutils) 8.22 */
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::old_io::print;
|
use std::io::Write;
|
||||||
use libc::c_char;
|
|
||||||
|
|
||||||
#[path = "../common/util.rs"] #[macro_use] mod util;
|
#[path = "../common/util.rs"] #[macro_use] mod util;
|
||||||
|
|
||||||
|
@ -30,12 +27,12 @@ extern {
|
||||||
|
|
||||||
fn get_userlogin() -> Option<String> {
|
fn get_userlogin() -> Option<String> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let login: *const libc::c_char = getlogin();
|
let login: *const libc::c_char = getlogin();
|
||||||
if login.is_null() {
|
if login.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(String::from_utf8_lossy(CStr::from_ptr(login).to_bytes()).to_string())
|
Some(String::from_utf8_lossy(CStr::from_ptr(login).to_bytes()).to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +54,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
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) => crash!(1, "Invalid options\n{}", f)
|
Err(f) => crash!(1, "Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
|
@ -68,7 +65,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {}", program);
|
println!(" {}", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("print user's login name", &opts).as_slice());
|
print!("{}", getopts::usage("print user's login name", &opts));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
|
@ -82,8 +79,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec() {
|
fn exec() {
|
||||||
match get_userlogin() {
|
match get_userlogin() {
|
||||||
Some(userlogin) => println!("{}", userlogin),
|
Some(userlogin) => println!("{}", userlogin),
|
||||||
None => println!("{}: no login name", NAME)
|
None => println!("{}: no login name", NAME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue