mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
commit
fc26e0cfea
3 changed files with 85 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -53,6 +53,7 @@ UNIX_PROGS := \
|
||||||
id \
|
id \
|
||||||
kill \
|
kill \
|
||||||
logname \
|
logname \
|
||||||
|
mkfifo \
|
||||||
sync \
|
sync \
|
||||||
tty \
|
tty \
|
||||||
uname \
|
uname \
|
||||||
|
|
82
mkfifo/mkfifo.rs
Normal file
82
mkfifo/mkfifo.rs
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#![crate_id(name="mkfifo", vers="1.0.0", author="Michael Gehring")]
|
||||||
|
#![feature(macro_rules)]
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the uutils coreutils package.
|
||||||
|
*
|
||||||
|
* (c) Michael Gehring <mg@ebfe.org>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern crate getopts;
|
||||||
|
extern crate libc;
|
||||||
|
|
||||||
|
use std::num::FromStrRadix;
|
||||||
|
use std::os;
|
||||||
|
use libc::funcs::posix88::stat_::mkfifo;
|
||||||
|
|
||||||
|
#[path = "../common/util.rs"]
|
||||||
|
mod util;
|
||||||
|
|
||||||
|
static NAME : &'static str = "mkfifo";
|
||||||
|
static VERSION : &'static str = "1.0.0";
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn main() { os::set_exit_status(uumain(os::args())); }
|
||||||
|
|
||||||
|
pub fn uumain(args: Vec<String>) -> int {
|
||||||
|
let opts = [
|
||||||
|
getopts::optopt("m", "mode", "file permissions for the fifo", "(default 0666)"),
|
||||||
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
|
getopts::optflag("V", "version", "output version information and exit"),
|
||||||
|
];
|
||||||
|
|
||||||
|
let matches = match getopts::getopts(args.tail(), opts) {
|
||||||
|
Ok(m) => m,
|
||||||
|
Err(err) => fail!("{}", err),
|
||||||
|
};
|
||||||
|
|
||||||
|
if matches.opt_present("version") {
|
||||||
|
println!("{} {}", NAME, VERSION);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches.opt_present("help") || matches.free.is_empty() {
|
||||||
|
println!("{} {}", NAME, VERSION);
|
||||||
|
println!("");
|
||||||
|
println!("Usage:");
|
||||||
|
println!(" {} [OPTIONS] NAME...", NAME);
|
||||||
|
println!("");
|
||||||
|
print!("{}", getopts::usage("Create a FIFO with the given name.", opts.as_slice()).as_slice());
|
||||||
|
if matches.free.is_empty() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mode = match matches.opt_str("m") {
|
||||||
|
Some(m) => match FromStrRadix::from_str_radix(m.as_slice(), 8) {
|
||||||
|
Some(m) => m,
|
||||||
|
None => {
|
||||||
|
show_error!("invalid mode");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => 0o666,
|
||||||
|
};
|
||||||
|
|
||||||
|
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() as uint));
|
||||||
|
exit_status = 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_status
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ extern crate kill;
|
||||||
extern crate logname;
|
extern crate logname;
|
||||||
extern crate md5sum;
|
extern crate md5sum;
|
||||||
extern crate mkdir;
|
extern crate mkdir;
|
||||||
|
extern crate mkfifo;
|
||||||
extern crate nl;
|
extern crate nl;
|
||||||
extern crate paste;
|
extern crate paste;
|
||||||
extern crate printenv;
|
extern crate printenv;
|
||||||
|
@ -94,6 +95,7 @@ fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
||||||
map.insert("logname", logname::uumain);
|
map.insert("logname", logname::uumain);
|
||||||
map.insert("md5sum", md5sum::uumain);
|
map.insert("md5sum", md5sum::uumain);
|
||||||
map.insert("mkdir", mkdir::uumain);
|
map.insert("mkdir", mkdir::uumain);
|
||||||
|
map.insert("mkfifo", mkfifo::uumain);
|
||||||
map.insert("nl", nl::uumain);
|
map.insert("nl", nl::uumain);
|
||||||
map.insert("paste", paste::uumain);
|
map.insert("paste", paste::uumain);
|
||||||
map.insert("printenv", printenv::uumain);
|
map.insert("printenv", printenv::uumain);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue