mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
update uses of libc 0.1.x and deprecated stdlib uses
This commit is contained in:
parent
10a2c5c224
commit
b20b2cca19
16 changed files with 40 additions and 39 deletions
|
@ -63,7 +63,7 @@ all = [
|
||||||
"tac",
|
"tac",
|
||||||
"tail",
|
"tail",
|
||||||
"tee",
|
"tee",
|
||||||
"test",
|
"test_uu",
|
||||||
"timeout",
|
"timeout",
|
||||||
"touch",
|
"touch",
|
||||||
"tr",
|
"tr",
|
||||||
|
@ -139,7 +139,7 @@ sync = { optional=true, path="src/sync" }
|
||||||
tac = { optional=true, path="src/tac" }
|
tac = { optional=true, path="src/tac" }
|
||||||
tail = { optional=true, path="src/tail" }
|
tail = { optional=true, path="src/tail" }
|
||||||
tee = { optional=true, path="src/tee" }
|
tee = { optional=true, path="src/tee" }
|
||||||
test = { optional=true, path="src/test" }
|
test_uu = { optional=true, path="src/test" }
|
||||||
timeout = { optional=true, path="src/timeout" }
|
timeout = { optional=true, path="src/timeout" }
|
||||||
touch = { optional=true, path="src/touch" }
|
touch = { optional=true, path="src/touch" }
|
||||||
tr = { optional=true, path="src/tr" }
|
tr = { optional=true, path="src/tr" }
|
||||||
|
|
|
@ -18,9 +18,8 @@ use getopts::Options;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::intrinsics::{copy_nonoverlapping};
|
use std::intrinsics::{copy_nonoverlapping};
|
||||||
use std::io::{stdout, stdin, stderr, Write, Read, Result};
|
use std::io::{stdout, stdin, stderr, Write, Read, Result};
|
||||||
use libc::consts::os::posix88::STDIN_FILENO;
|
use libc::STDIN_FILENO;
|
||||||
use libc::funcs::posix88::unistd::isatty;
|
use libc::{c_int, isatty};
|
||||||
use libc::types::os::arch::c95::c_int;
|
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -14,7 +14,7 @@ extern crate libc;
|
||||||
|
|
||||||
use c_types::{get_pw_from_args, get_group};
|
use c_types::{get_pw_from_args, get_group};
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use libc::funcs::posix88::unistd::{setgid, setuid};
|
use libc::{setgid, setuid};
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
|
|
@ -13,7 +13,7 @@ use self::libc::time_t;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use self::libc::int32_t;
|
use self::libc::int32_t;
|
||||||
|
|
||||||
use self::libc::funcs::posix88::unistd::getgroups;
|
use self::libc::getgroups;
|
||||||
|
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use libc::{c_int, pid_t};
|
use libc::{c_int, pid_t};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -17,6 +16,7 @@ use std::process::Child;
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use time::{Duration, get_time};
|
use time::{Duration, get_time};
|
||||||
|
use std::time::Duration as StdDuration;
|
||||||
|
|
||||||
// This is basically sys::unix::process::ExitStatus
|
// This is basically sys::unix::process::ExitStatus
|
||||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||||
|
@ -76,8 +76,8 @@ pub trait ChildExt {
|
||||||
|
|
||||||
impl ChildExt for Child {
|
impl ChildExt for Child {
|
||||||
fn send_signal(&mut self, signal: usize) -> io::Result<()> {
|
fn send_signal(&mut self, signal: usize) -> io::Result<()> {
|
||||||
if unsafe { libc::funcs::posix88::signal::kill(self.id() as pid_t,
|
if unsafe { libc::kill(self.id() as pid_t,
|
||||||
signal as i32) } != 0 {
|
signal as i32) } != 0 {
|
||||||
Err(io::Error::last_os_error())
|
Err(io::Error::last_os_error())
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -125,7 +125,7 @@ impl ChildExt for Child {
|
||||||
return Ok(None)
|
return Ok(None)
|
||||||
}
|
}
|
||||||
let ms = (target - get_time()).num_milliseconds() as u32;
|
let ms = (target - get_time()).num_milliseconds() as u32;
|
||||||
exitstatus = cvar.wait_timeout_ms(exitstatus, ms).unwrap().0;
|
exitstatus = cvar.wait_timeout(exitstatus, StdDuration::new(0, ms*1000)).unwrap().0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn Option<Result<ExitStatus>> into Result<Option<ExitStatus>>
|
// Turn Option<Result<ExitStatus>> into Result<Option<ExitStatus>>
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use libc::{getgid, getuid, uid_t};
|
use libc::{getgid, getuid, uid_t, getegid, geteuid, getlogin};
|
||||||
use libc::funcs::posix88::unistd::{getegid, geteuid, getlogin};
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ptr::read;
|
use std::ptr::read;
|
||||||
|
|
|
@ -182,7 +182,7 @@ fn kill(signalname: &str, pids: std::vec::Vec<String>) -> i32 {
|
||||||
for pid in pids.iter() {
|
for pid in pids.iter() {
|
||||||
match pid.parse::<usize>() {
|
match pid.parse::<usize>() {
|
||||||
Ok(x) => {
|
Ok(x) => {
|
||||||
if unsafe { libc::funcs::posix88::signal::kill(x as pid_t, signal_value as c_int) } != 0 {
|
if unsafe { libc::kill(x as pid_t, signal_value as c_int) } != 0 {
|
||||||
show_error!("{}", Error::last_os_error());
|
show_error!("{}", Error::last_os_error());
|
||||||
status = 1;
|
status = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use libc::funcs::posix88::stat_::mkfifo;
|
use libc::mkfifo;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,8 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use libc::c_char;
|
use libc::{c_char, signal, dup2, execvp, isatty};
|
||||||
use libc::funcs::posix01::signal::signal;
|
use libc::{SIG_IGN, SIGHUP};
|
||||||
use libc::funcs::posix88::unistd::{dup2, execvp, isatty};
|
|
||||||
use libc::consts::os::posix01::SIG_IGN;
|
|
||||||
use libc::consts::os::posix88::SIGHUP;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
|
|
|
@ -13,7 +13,8 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::thread::sleep_ms;
|
use std::thread::{self};
|
||||||
|
use std::time::Duration;
|
||||||
use std::u32::MAX as U32_MAX;
|
use std::u32::MAX as U32_MAX;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
|
@ -75,7 +76,7 @@ fn sleep(args: Vec<String>) {
|
||||||
let sleep_dur = if sleep_time > (U32_MAX as f64) {
|
let sleep_dur = if sleep_time > (U32_MAX as f64) {
|
||||||
U32_MAX
|
U32_MAX
|
||||||
} else {
|
} else {
|
||||||
(1000.0 * sleep_time) as u32
|
(1000000.0 * sleep_time) as u32
|
||||||
};
|
};
|
||||||
sleep_ms(sleep_dur);
|
thread::sleep(Duration::new(0, sleep_dur));
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,8 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use libc::consts::os::posix88::STDIN_FILENO;
|
use libc::STDIN_FILENO;
|
||||||
use libc::funcs::posix88::unistd::isatty;
|
use libc::{c_int, isatty};
|
||||||
use libc::types::os::arch::c95::c_int;
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Read, stdin, Write};
|
use std::io::{BufRead, BufReader, Read, stdin, Write};
|
||||||
|
|
|
@ -17,7 +17,8 @@ use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Read, stdin, stdout, Write};
|
use std::io::{BufRead, BufReader, Read, stdin, stdout, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
use std::thread::sleep_ms;
|
use std::thread::sleep;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -273,7 +274,7 @@ fn tail<T: Read>(reader: &mut BufReader<T>, mut line_count: usize, mut byte_coun
|
||||||
|
|
||||||
// if we follow the file, sleep a bit and print the rest if the file has grown.
|
// if we follow the file, sleep a bit and print the rest if the file has grown.
|
||||||
while follow {
|
while follow {
|
||||||
sleep_ms(sleep_msec);
|
sleep(Duration::new(0, sleep_msec*1000));
|
||||||
for io_line in reader.lines() {
|
for io_line in reader.lines() {
|
||||||
match io_line {
|
match io_line {
|
||||||
Ok(line) => print!("{}", line),
|
Ok(line) => print!("{}", line),
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "test"
|
name = "test_uu"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
authors = []
|
authors = []
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "test"
|
name = "test_uu"
|
||||||
path = "test.rs"
|
path = "test.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![crate_name = "test"]
|
#![crate_name = "test_uu"]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -15,11 +15,8 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use libc::consts::os::posix88::{S_IFMT, S_IFLNK, S_IFREG};
|
use libc::{S_IFMT, S_IFLNK, S_IFREG};
|
||||||
use libc::funcs::posix01::stat_::lstat;
|
use libc::{lstat, unlink, c_char, stat};
|
||||||
use libc::funcs::posix88::unistd::unlink;
|
|
||||||
use libc::types::os::arch::c95::c_char;
|
|
||||||
use libc::types::os::arch::posix01::stat;
|
|
||||||
use std::io::{Error, ErrorKind, Write};
|
use std::io::{Error, ErrorKind, Write};
|
||||||
use std::mem::uninitialized;
|
use std::mem::uninitialized;
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,21 @@ static VERSION: &'static str = "0.0.1";
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/uutils_map.rs"));
|
include!(concat!(env!("OUT_DIR"), "/uutils_map.rs"));
|
||||||
|
|
||||||
|
fn name_sub(util_name: &str) -> &str {
|
||||||
|
match util_name {
|
||||||
|
"test" => "test_uu",
|
||||||
|
"test_uu" => "test",
|
||||||
|
x @ _ => x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn usage(cmap: &UtilityMap) {
|
fn usage(cmap: &UtilityMap) {
|
||||||
println!("{} {}", NAME, VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
println!("");
|
println!("");
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {} [util [arguments...]]\n", NAME);
|
println!(" {} [util [arguments...]]\n", NAME);
|
||||||
println!("Currently defined functions:");
|
println!("Currently defined functions:");
|
||||||
let mut utils: Vec<&str> = cmap.keys().map(|&s| s).collect();
|
let mut utils: Vec<&str> = cmap.keys().map(|&s| name_sub(s)).collect();
|
||||||
utils.sort();
|
utils.sort();
|
||||||
for util in utils.iter() {
|
for util in utils.iter() {
|
||||||
println!("\t{}", util);
|
println!("\t{}", util);
|
||||||
|
@ -64,7 +72,7 @@ fn main() {
|
||||||
args.remove(0);
|
args.remove(0);
|
||||||
let util = &args[0][..];
|
let util = &args[0][..];
|
||||||
|
|
||||||
match umap.get(util) {
|
match umap.get(name_sub(util)) {
|
||||||
Some(&uumain) => {
|
Some(&uumain) => {
|
||||||
std::process::exit(uumain(args.clone()));
|
std::process::exit(uumain(args.clone()));
|
||||||
}
|
}
|
||||||
|
@ -73,7 +81,7 @@ fn main() {
|
||||||
// see if they want help on a specific util
|
// see if they want help on a specific util
|
||||||
if args.len() >= 2 {
|
if args.len() >= 2 {
|
||||||
let util = &args[1][..];
|
let util = &args[1][..];
|
||||||
match umap.get(util) {
|
match umap.get(name_sub(util)) {
|
||||||
Some(&uumain) => {
|
Some(&uumain) => {
|
||||||
std::process::exit(uumain(vec![util.to_string(), "--help".to_string()]));
|
std::process::exit(uumain(vec![util.to_string(), "--help".to_string()]));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue