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

mkfifo, paste, shuf: fix build

This commit is contained in:
Michael Gehring 2015-01-10 13:48:42 +01:00
parent bd1922d155
commit 5402e69923
3 changed files with 15 additions and 16 deletions

View file

@ -12,6 +12,7 @@
extern crate getopts;
extern crate libc;
use std::ffi::CString;
use std::num::FromStrRadix;
use std::os;
use libc::funcs::posix88::stat_::mkfifo;
@ -23,7 +24,7 @@ mod util;
static NAME : &'static str = "mkfifo";
static VERSION : &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
pub fn uumain(args: Vec<String>) -> isize {
let opts = [
getopts::optopt("m", "mode", "file permissions for the fifo", "(default 0666)"),
getopts::optflag("h", "help", "display this help and exit"),
@ -66,13 +67,11 @@ pub fn uumain(args: Vec<String>) -> int {
let mut exit_status = 0;
for f in matches.free.iter() {
f.with_c_str(|name| {
let err = unsafe { mkfifo(name, mode) };
if err == -1 {
show_error!("creating '{}': {}", f, os::error_string(os::errno()));
exit_status = 1;
}
});
let err = unsafe { mkfifo(CString::from_slice(f.as_bytes()).as_ptr(), mode) };
if err == -1 {
show_error!("creating '{}': {}", f, os::error_string(os::errno()));
exit_status = 1;
}
}
exit_status

View file

@ -22,7 +22,7 @@ mod util;
static NAME: &'static str = "paste";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
pub fn uumain(args: Vec<String>) -> isize {
let program = args[0].clone();
let opts = [
@ -60,10 +60,10 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) {
let mut files: Vec<io::BufferedReader<Box<Reader>>> = filenames.into_iter().map(|name|
io::BufferedReader::new(
if name.as_slice() == "-" {
box io::stdio::stdin_raw() as Box<Reader>
Box::new(io::stdio::stdin_raw()) as Box<Reader>
} else {
let r = crash_if_err!(1, io::File::open(&Path::new(name)));
box r as Box<Reader>
Box::new(r) as Box<Reader>
}
)
).collect();

View file

@ -32,7 +32,7 @@ enum Mode {
static NAME: &'static str = "shuf";
static VERSION: &'static str = "0.0.1";
pub fn uumain(args: Vec<String>) -> int {
pub fn uumain(args: Vec<String>) -> isize {
let program = args[0].clone();
let opts = [
@ -157,16 +157,16 @@ enum WrappedRng {
impl WrappedRng {
fn next_u32(&mut self) -> u32 {
match self {
&WrappedRng::RngFile(ref mut r) => r.next_u32(),
&WrappedRng::RngDefault(ref mut r) => r.next_u32(),
&mut WrappedRng::RngFile(ref mut r) => r.next_u32(),
&mut WrappedRng::RngDefault(ref mut r) => r.next_u32(),
}
}
}
fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, outname: Option<String>, random: Option<String>) -> IoResult<()> {
let mut output = match outname {
Some(name) => box io::BufferedWriter::new(try!(io::File::create(&Path::new(name)))) as Box<Writer>,
None => box io::stdout() as Box<Writer>
Some(name) => Box::new(io::BufferedWriter::new(try!(io::File::create(&Path::new(name))))) as Box<Writer>,
None => Box::new(io::stdout()) as Box<Writer>
};
let mut rng = match random {
Some(name) => WrappedRng::RngFile(rand::reader::ReaderRng::new(try!(io::File::open(&Path::new(name))))),