1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #250 from xanderfomin/sync

GNU sync implementation
This commit is contained in:
Arcterus 2014-06-15 11:07:50 -07:00
commit 2739e414b3
3 changed files with 72 additions and 6 deletions

View file

@ -43,17 +43,18 @@ PROGS := \
tail \
UNIX_PROGS := \
groups \
hostid \
hostname \
id \
kill \
logname \
users \
whoami \
sync \
tty \
groups \
id \
uname \
uptime \
uname
users \
whoami
ifneq ($(OS),Windows_NT)
PROGS := $(PROGS) $(UNIX_PROGS)

View file

@ -171,7 +171,6 @@ To do
- stat
- stdbuf
- stty (in progress)
- sync
- tail (not all features implemented)
- test
- timeout

66
sync/sync.rs Normal file
View file

@ -0,0 +1,66 @@
#![crate_id(name="sync", vers="1.0.0", author="Alexander Fomin")]
/*
* This file is part of the uutils coreutils package.
*
* (c) Alexander Fomin <xander.fomin@ya.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/* Last synced with: sync (GNU coreutils) 8.13 */
extern crate getopts;
extern crate libc;
use std::os;
use getopts::{optflag, getopts, usage};
extern {
fn sync() -> libc::c_void;
}
#[allow(dead_code)]
fn main () { os::set_exit_status(uumain(os::args())); }
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0);
let options = [
optflag("h", "help", "display this help and exit"),
optflag("V", "version", "output version information and exit")
];
let matches = match getopts(args.tail(), options) {
Ok(m) => { m }
_ => { help(program.as_slice(), options); return 0 }
};
if matches.opt_present("h") {
help(program.as_slice(), options);
return 0
}
if matches.opt_present("V") {
version();
return 0
}
unsafe {
sync()
};
0
}
fn version() {
println!("sync (uutils) 1.0.0");
println!("The MIT License");
println!("");
println!("Author -- Alexander Fomin.");
}
fn help(program: &str, options: &[getopts::OptGroup]) {
println!("Usage: {:s} [OPTION]", program);
print!("{:s}", usage("Force changed blocks to disk, update the super block.", options));
}