1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 13:37:48 +00:00

Merge pull request #592 from jbcrail/fix-nice

Fix nice.
This commit is contained in:
Heather 2015-05-12 07:06:43 +03:00
commit 60e3603410

View file

@ -1,5 +1,5 @@
#![crate_name = "nice"] #![crate_name = "nice"]
#![feature(collections, core, old_io, os, 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.
@ -14,8 +14,7 @@ extern crate getopts;
extern crate libc; extern crate libc;
use std::ffi::CString; use std::ffi::CString;
use std::old_io::IoError; use std::io::{Error, Write};
use std::os;
use libc::{c_char, c_int, execvp}; use libc::{c_char, c_int, execvp};
const NAME: &'static str = "nice"; const NAME: &'static str = "nice";
@ -40,7 +39,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(err) => { Err(err) => {
show_error!("{}", err); show_error!("{}", err);
@ -67,8 +66,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
0 0
} else { } else {
let mut niceness = unsafe { getpriority(PRIO_PROCESS, 0) }; let mut niceness = unsafe { getpriority(PRIO_PROCESS, 0) };
if os::errno() != 0 { if Error::last_os_error().raw_os_error().unwrap() != 0 {
show_error!("{}", IoError::last_error()); show_error!("{}", Error::last_os_error());
return 125; return 125;
} }
@ -79,7 +78,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
Try \"{} --help\" for more information.", args[0]); Try \"{} --help\" for more information.", args[0]);
return 125; return 125;
} }
match nstr.as_slice().parse() { match nstr.parse() {
Ok(num) => num, Ok(num) => num,
Err(e)=> { Err(e)=> {
show_error!("\"{}\" is not a valid number: {}", nstr, e); show_error!("\"{}\" is not a valid number: {}", nstr, e);
@ -98,8 +97,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
niceness += adjustment; niceness += adjustment;
unsafe { setpriority(PRIO_PROCESS, 0, niceness); } unsafe { setpriority(PRIO_PROCESS, 0, niceness); }
if os::errno() != 0 { if Error::last_os_error().raw_os_error().unwrap() != 0 {
show_warning!("{}", IoError::last_error()); show_warning!("{}", Error::last_os_error());
} }
let cstrs: Vec<CString> = matches.free.iter().map(|x| CString::new(x.as_bytes()).unwrap()).collect(); let cstrs: Vec<CString> = matches.free.iter().map(|x| CString::new(x.as_bytes()).unwrap()).collect();
@ -107,7 +106,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
args.push(0 as *const c_char); args.push(0 as *const c_char);
unsafe { execvp(args[0], args.as_mut_ptr()); } unsafe { execvp(args[0], args.as_mut_ptr()); }
show_error!("{}", IoError::last_error()); show_error!("{}", Error::last_os_error());
if os::errno() as c_int == libc::ENOENT { 127 } else { 126 } if Error::last_os_error().raw_os_error().unwrap() as c_int == libc::ENOENT { 127 } else { 126 }
} }
} }