mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
Merge pull request #564 from jbcrail/fix-hostid-pwd
Fix hostid and pwd.
This commit is contained in:
commit
b830fc87b6
2 changed files with 17 additions and 28 deletions
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "hostid"]
|
#![crate_name = "hostid"]
|
||||||
#![feature(collections, core, rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -10,22 +10,14 @@
|
||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate collections;
|
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
use getopts::{
|
use getopts::{getopts, optflag, usage};
|
||||||
getopts,
|
|
||||||
optflag,
|
|
||||||
usage,
|
|
||||||
};
|
|
||||||
|
|
||||||
use libc::{c_long};
|
use libc::{c_long};
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -42,15 +34,12 @@ pub enum Mode {
|
||||||
Version,
|
Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Copy for Mode {}
|
|
||||||
|
|
||||||
//currently rust libc interface doesn't include gethostid
|
//currently rust libc interface doesn't include gethostid
|
||||||
extern {
|
extern {
|
||||||
pub fn gethostid() -> c_long;
|
pub fn gethostid() -> c_long;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
||||||
let opts = [
|
let opts = [
|
||||||
optflag("", "help", "display this help and exit"),
|
optflag("", "help", "display this help and exit"),
|
||||||
optflag("", "version", "output version information and exit"),
|
optflag("", "version", "output version information and exit"),
|
||||||
|
@ -58,11 +47,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
||||||
let usage = usage("[options]", &opts);
|
let usage = usage("[options]", &opts);
|
||||||
|
|
||||||
|
let matches = match getopts(&args[1..], &opts) {
|
||||||
let matches = match getopts(args.tail(), &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
show_error!("{}\n{}", e, get_help_text(NAME, usage.as_slice()));
|
show_error!("{}\n{}", e, get_help_text(NAME, usage.as_ref()));
|
||||||
return EXIT_ERR;
|
return EXIT_ERR;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -77,7 +65,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
Mode::HostId => hostid(),
|
Mode::HostId => hostid(),
|
||||||
Mode::Help => help(NAME, usage.as_slice()),
|
Mode::Help => help(NAME, usage.as_ref()),
|
||||||
Mode::Version => version(),
|
Mode::Version => version(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +85,11 @@ fn help(progname: &str, usage: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hostid() {
|
fn hostid() {
|
||||||
|
/*
|
||||||
/* POSIX says gethostid returns a "32-bit identifier" but is silent
|
* POSIX says gethostid returns a "32-bit identifier" but is silent
|
||||||
whether it's sign-extended. Turn off any sign-extension. This
|
* whether it's sign-extended. Turn off any sign-extension. This
|
||||||
is a no-op unless unsigned int is wider than 32 bits. */
|
* is a no-op unless unsigned int is wider than 32 bits.
|
||||||
|
*/
|
||||||
|
|
||||||
let mut result:c_long;
|
let mut result:c_long;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "pwd"]
|
#![crate_name = "pwd"]
|
||||||
#![feature(collections, core, old_io, os, rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,7 +13,8 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::old_io::print;
|
use std::env;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -29,7 +30,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
getopts::optflag("", "version", "output version information and exit"),
|
getopts::optflag("", "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) => {
|
Err(f) => {
|
||||||
crash!(1, "Invalid options\n{}", f)
|
crash!(1, "Invalid options\n{}", f)
|
||||||
|
@ -42,14 +43,13 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0} [OPTION] NAME...", program);
|
println!(" {0} [OPTION] NAME...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Print the full filename of the current working directory.", &opts).as_slice());
|
print!("{}", getopts::usage("Print the full filename of the current working directory.", &opts));
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("pwd version: {}", VERSION);
|
println!("pwd version: {}", VERSION);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
let cwd = std::os::getcwd();
|
println!("{}", env::current_dir().unwrap().display());
|
||||||
println!("{}", cwd.unwrap().display());
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue