1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-02 14:07:46 +00:00

Merge pull request #566 from jbcrail/update-tty

Update tty and ignore build directories.
This commit is contained in:
Heather 2015-05-04 08:32:26 +03:00
commit 15acf2a2b5
2 changed files with 44 additions and 35 deletions

3
.gitignore vendored
View file

@ -2,7 +2,10 @@
/target/ /target/
/tmp/ /tmp/
/busybox/ /busybox/
/deps/regex/
/deps/rust-crypto/
/deps/target/ /deps/target/
/deps/time/
*~ *~
.*.swp .*.swp
.*.swo .*.swo

View file

@ -15,8 +15,9 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use getopts::{getopts, optflag};
use std::ffi::CStr; use std::ffi::CStr;
use getopts::{optflag,getopts}; use std::io::Write;
#[path = "../common/util.rs"] #[path = "../common/util.rs"]
#[macro_use] #[macro_use]
@ -28,23 +29,31 @@ extern {
} }
static NAME: &'static str = "tty"; static NAME: &'static str = "tty";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 { pub fn uumain(args: Vec<String>) -> i32 {
let options = [ let options = [
optflag("s", "silent", "print nothing, only return an exit status") optflag("s", "silent", "print nothing, only return an exit status"),
optflag("h", "help", "display this help and exit"),
optflag("V", "version", "output version information and exit")
]; ];
let silent = match getopts(&args[1..], &options) { let matches = match getopts(&args[1..], &options) {
Ok(m) => { Ok(m) => m,
m.opt_present("s")
},
Err(f) => { Err(f) => {
println!("{}", f); crash!(2, "{}", f)
usage();
return 2;
} }
}; };
if matches.opt_present("help") {
let usage = getopts::usage("Print the file name of the terminal connected to standard input.", &options);
println!("Usage: {} [OPTION]...\n{}", NAME, usage);
} else if matches.opt_present("version") {
println!("{} {}", NAME, VERSION);
} else {
let silent = matches.opt_present("s");
let tty = unsafe { let tty = unsafe {
let ptr = ttyname(libc::STDIN_FILENO); let ptr = ttyname(libc::STDIN_FILENO);
if !ptr.is_null() { if !ptr.is_null() {
@ -62,17 +71,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
} }
} }
let exit_code = unsafe { return unsafe {
if isatty(libc::STDIN_FILENO) == 1 { if isatty(libc::STDIN_FILENO) == 1 {
libc::EXIT_SUCCESS libc::EXIT_SUCCESS
} else { } else {
libc::EXIT_FAILURE libc::EXIT_FAILURE
} }
}; };
}
exit_code 0
}
fn usage() {
println!("usage: {} [-s]", NAME);
} }