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

Merge pull request #564 from jbcrail/fix-hostid-pwd

Fix hostid and pwd.
This commit is contained in:
Michael Gehring 2015-05-03 11:40:07 +02:00
commit b830fc87b6
2 changed files with 17 additions and 28 deletions

View file

@ -1,5 +1,5 @@
#![crate_name = "hostid"]
#![feature(collections, core, rustc_private)]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@ -10,22 +10,14 @@
* that was distributed with this source code.
*/
extern crate getopts;
extern crate collections;
extern crate serialize;
extern crate libc;
#[macro_use] extern crate log;
use getopts::{
getopts,
optflag,
usage,
};
use getopts::{getopts, optflag, usage};
use libc::{c_long};
use std::io::Write;
#[path = "../common/util.rs"]
#[macro_use]
@ -42,15 +34,12 @@ pub enum Mode {
Version,
}
impl Copy for Mode {}
//currently rust libc interface doesn't include gethostid
extern {
pub fn gethostid() -> c_long;
}
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
optflag("", "help", "display this help 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 matches = match getopts(args.tail(), &opts) {
let matches = match getopts(&args[1..], &opts) {
Ok(m) => m,
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;
},
};
@ -77,7 +65,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
match mode {
Mode::HostId => hostid(),
Mode::Help => help(NAME, usage.as_slice()),
Mode::Help => help(NAME, usage.as_ref()),
Mode::Version => version(),
}
@ -97,10 +85,11 @@ fn help(progname: &str, usage: &str) {
}
fn hostid() {
/* POSIX says gethostid returns a "32-bit identifier" but is silent
whether it's sign-extended. Turn off any sign-extension. This
is a no-op unless unsigned int is wider than 32 bits. */
/*
* POSIX says gethostid returns a "32-bit identifier" but is silent
* whether it's sign-extended. Turn off any sign-extension. This
* is a no-op unless unsigned int is wider than 32 bits.
*/
let mut result:c_long;
unsafe {

View file

@ -1,5 +1,5 @@
#![crate_name = "pwd"]
#![feature(collections, core, old_io, os, rustc_private)]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@ -13,7 +13,8 @@
extern crate getopts;
extern crate libc;
use std::old_io::print;
use std::env;
use std::io::Write;
#[path = "../common/util.rs"]
#[macro_use]
@ -29,7 +30,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
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,
Err(f) => {
crash!(1, "Invalid options\n{}", f)
@ -42,14 +43,13 @@ pub fn uumain(args: Vec<String>) -> i32 {
println!("Usage:");
println!(" {0} [OPTION] NAME...", program);
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") {
println!("pwd version: {}", VERSION);
return 0;
} else {
let cwd = std::os::getcwd();
println!("{}", cwd.unwrap().display());
println!("{}", env::current_dir().unwrap().display());
return 0;
}