1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 04:27:45 +00:00

Merge pull request #489 from ebfe/fix-build-master

Partially fix build with rust master
This commit is contained in:
Heather 2015-01-09 11:47:48 +03:00
commit 3580c69d00
17 changed files with 65 additions and 40 deletions

2
deps/rust-crypto vendored

@ -1 +1 @@
Subproject commit ebf18b21551cccba2aa75ea2372b2e85ab4cf89a Subproject commit c85bfa94d5003f839540536a6d42ecea094d8a45

2
deps/time vendored

@ -1 +1 @@
Subproject commit a0a0dedc41fac4d2504db533b70af1686ec19d15 Subproject commit 00121035e51e1df14d5cd3a3233905f43e5c93a9

View file

@ -14,7 +14,9 @@ extern crate libc;
use getopts::{optflag, optopt, getopts, usage}; use getopts::{optflag, optopt, getopts, usage};
use c_types::{get_pw_from_args, get_group}; use c_types::{get_pw_from_args, get_group};
use libc::funcs::posix88::unistd::{execvp, setuid, setgid}; use libc::funcs::posix88::unistd::{execvp, setuid, setgid};
use std::ffi::c_str_to_bytes;
use std::io::fs::PathExtensions; use std::io::fs::PathExtensions;
use std::iter::FromIterator;
#[path = "../common/util.rs"] #[macro_use] mod util; #[path = "../common/util.rs"] #[macro_use] mod util;
#[path = "../common/c_types.rs"] mod c_types; #[path = "../common/c_types.rs"] mod c_types;
@ -191,8 +193,9 @@ fn set_user(user: &str) {
fn strerror(errno: i32) -> String { fn strerror(errno: i32) -> String {
unsafe { unsafe {
let err = libc::funcs::c95::string::strerror(errno); let err = libc::funcs::c95::string::strerror(errno) as *const libc::c_char;
String::from_raw_buf(err as *const u8) let bytes= c_str_to_bytes(&err);
String::from_utf8_lossy(bytes).to_string()
} }
} }

View file

@ -11,7 +11,7 @@
extern crate getopts; extern crate getopts;
use std::cmp::Ord; use std::cmp::Ordering;
use std::io::{BufferedReader, IoResult, print}; use std::io::{BufferedReader, IoResult, print};
use std::io::fs::File; use std::io::fs::File;
use std::io::stdio::{stdin, StdinReader}; use std::io::stdio::{stdin, StdinReader};
@ -60,33 +60,33 @@ impl LineReader {
fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) { fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) {
let delim = Vec::from_fn(4, |col| mkdelim(col, opts)); let delim : Vec<String> = range(0, 4).map(|col| mkdelim(col, opts)).collect();
let mut ra = a.read_line(); let mut ra = a.read_line();
let mut rb = b.read_line(); let mut rb = b.read_line();
while ra.is_ok() || rb.is_ok() { while ra.is_ok() || rb.is_ok() {
let ord = match (ra.clone(), rb.clone()) { let ord = match (ra.clone(), rb.clone()) {
(Err(_), Ok(_)) => Greater, (Err(_), Ok(_)) => Ordering::Greater,
(Ok(_) , Err(_)) => Less, (Ok(_) , Err(_)) => Ordering::Less,
(Ok(s0), Ok(s1)) => s0.cmp(&s1), (Ok(s0), Ok(s1)) => s0.cmp(&s1),
_ => unreachable!(), _ => unreachable!(),
}; };
match ord { match ord {
Less => { Ordering::Less => {
if !opts.opt_present("1") { if !opts.opt_present("1") {
print!("{}{}", delim[1], ra.map(ensure_nl).unwrap()); print!("{}{}", delim[1], ra.map(ensure_nl).unwrap());
} }
ra = a.read_line(); ra = a.read_line();
} }
Greater => { Ordering::Greater => {
if !opts.opt_present("2") { if !opts.opt_present("2") {
print!("{}{}", delim[2], rb.map(ensure_nl).unwrap()); print!("{}{}", delim[2], rb.map(ensure_nl).unwrap());
} }
rb = b.read_line(); rb = b.read_line();
} }
Equal => { Ordering::Equal => {
if !opts.opt_present("3") { if !opts.opt_present("3") {
print!("{}{}", delim[3], ra.map(ensure_nl).unwrap()); print!("{}{}", delim[3], ra.map(ensure_nl).unwrap());
} }

View file

@ -15,6 +15,8 @@ use self::libc::int32_t;
use self::libc::funcs::posix88::unistd::getgroups; use self::libc::funcs::posix88::unistd::getgroups;
use std::ffi::{c_str_to_bytes, CString};
use std::iter::repeat;
use std::vec::Vec; use std::vec::Vec;
use std::os; use std::os;
@ -122,7 +124,7 @@ pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
let id = username.parse::<u32>().unwrap(); let id = username.parse::<u32>().unwrap();
let pw_pointer = unsafe { getpwuid(id as uid_t) }; let pw_pointer = unsafe { getpwuid(id as uid_t) };
if pw_pointer.is_not_null() { if !pw_pointer.is_null() {
Some(unsafe { read(pw_pointer) }) Some(unsafe { read(pw_pointer) })
} else { } else {
crash!(1, "{}: no such user", username); crash!(1, "{}: no such user", username);
@ -131,9 +133,10 @@ pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
// Passed the username as a string // Passed the username as a string
} else { } else {
let pw_pointer = unsafe { let pw_pointer = unsafe {
getpwnam(username.as_slice().to_c_str().into_inner() as *const libc::c_char) let cstr = CString::from_slice(username.as_bytes());
getpwnam(cstr.as_slice_with_nul().as_ptr())
}; };
if pw_pointer.is_not_null() { if !pw_pointer.is_null() {
Some(unsafe { read(pw_pointer) }) Some(unsafe { read(pw_pointer) })
} else { } else {
crash!(1, "{}: no such user", username); crash!(1, "{}: no such user", username);
@ -148,10 +151,13 @@ pub fn get_group(groupname: &str) -> Option<c_group> {
let group = if groupname.chars().all(|c| c.is_digit(10)) { let group = if groupname.chars().all(|c| c.is_digit(10)) {
unsafe { getgrgid(groupname.parse().unwrap()) } unsafe { getgrgid(groupname.parse().unwrap()) }
} else { } else {
unsafe { getgrnam(groupname.to_c_str().into_inner() as *const c_char) } unsafe {
let cstr = CString::from_slice(groupname.as_bytes());
getgrnam(cstr.as_slice_with_nul().as_ptr() as *const c_char)
}
}; };
if group.is_not_null() { if !group.is_null() {
Some(unsafe { read(group) }) Some(unsafe { read(group) })
} }
else { else {
@ -199,7 +205,7 @@ pub fn get_groups() -> Result<Vec<gid_t>, uint> {
return Err(os::errno()); return Err(os::errno());
} }
let mut groups = Vec::from_elem(ngroups as uint, 0 as gid_t); let mut groups : Vec<gid_t>= repeat(0).take(ngroups as uint).collect();
let ngroups = unsafe { getgroups(ngroups, groups.as_mut_ptr()) }; let ngroups = unsafe { getgroups(ngroups, groups.as_mut_ptr()) };
if ngroups == -1 { if ngroups == -1 {
Err(os::errno()) Err(os::errno())
@ -222,9 +228,11 @@ pub fn group(possible_pw: Option<c_passwd>, nflag: bool) {
for &g in groups.iter() { for &g in groups.iter() {
if nflag { if nflag {
let group = unsafe { getgrgid(g) }; let group = unsafe { getgrgid(g) };
if group.is_not_null() { if !group.is_null() {
let name = unsafe { let name = unsafe {
String::from_raw_buf(read(group).gr_name as *const u8) let gname = read(group).gr_name;
let bytes= c_str_to_bytes(&gname);
String::from_utf8_lossy(bytes).to_string()
}; };
print!("{} ", name); print!("{} ", name);
} }

View file

@ -71,7 +71,7 @@ fn detect_algo(program: &str, matches: &getopts::Matches) -> (&'static str, Box<
"sha512sum" => ("SHA512", box Sha512::new() as Box<Digest>), "sha512sum" => ("SHA512", box Sha512::new() as Box<Digest>),
_ => { _ => {
{ {
let set_or_crash = |n, val| -> () { let mut set_or_crash = |&mut: n, val| -> () {
if alg.is_some() { crash!(1, "You cannot combine multiple hash algorithms!") }; if alg.is_some() { crash!(1, "You cannot combine multiple hash algorithms!") };
name = n; name = n;
alg = Some(val); alg = Some(val);

View file

@ -17,6 +17,7 @@ extern crate libc;
use std::collections::hash_set::HashSet; use std::collections::hash_set::HashSet;
use std::io::net::addrinfo; use std::io::net::addrinfo;
use std::iter::repeat;
use std::str; use std::str;
use getopts::{optflag, getopts, usage}; use getopts::{optflag, getopts, usage};
@ -130,8 +131,7 @@ fn help_menu(program: &str, options: &[getopts::OptGroup]) {
fn xgethostname() -> String { fn xgethostname() -> String {
let namelen = 256u; let namelen = 256u;
let mut name = Vec::from_elem(namelen, 0u8); let mut name : Vec<u8> = repeat(0).take(namelen).collect();
let err = unsafe { let err = unsafe {
gethostname (name.as_mut_ptr() as *mut libc::c_char, gethostname (name.as_mut_ptr() as *mut libc::c_char,
namelen as libc::size_t) namelen as libc::size_t)

View file

@ -16,6 +16,7 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::ffi::c_str_to_bytes;
use std::io::print; use std::io::print;
use libc::c_char; use libc::c_char;
@ -32,7 +33,7 @@ fn get_userlogin() -> Option<String> {
if login.is_null() { if login.is_null() {
None None
} else { } else {
Some(String::from_raw_buf(login as *const u8)) Some(String::from_utf8_lossy(c_str_to_bytes(&login)).to_string())
} }
} }
} }

View file

@ -13,6 +13,7 @@ extern crate getopts;
extern crate libc; extern crate libc;
use std::io; use std::io;
use std::iter::repeat;
#[path = "../common/util.rs"] #[path = "../common/util.rs"]
#[macro_use] #[macro_use]
@ -88,7 +89,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) {
println!("{}", output.as_slice().slice_to(output.len() - 1)); println!("{}", output.as_slice().slice_to(output.len() - 1));
} }
} else { } else {
let mut eof = Vec::from_elem(files.len(), false); let mut eof : Vec<bool> = repeat(false).take(files.len()).collect();
loop { loop {
let mut output = "".to_string(); let mut output = "".to_string();
let mut eof_count = 0; let mut eof_count = 0;

View file

@ -151,7 +151,7 @@ fn shuf(input: Vec<String>, mode: Mode, repeat: bool, zero: bool, count: uint, o
enum WrappedRng { enum WrappedRng {
RngFile(rand::reader::ReaderRng<io::File>), RngFile(rand::reader::ReaderRng<io::File>),
RngDefault(rand::TaskRng), RngDefault(rand::ThreadRng),
} }
impl WrappedRng { impl WrappedRng {
@ -170,7 +170,7 @@ fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, out
}; };
let mut rng = match random { let mut rng = match random {
Some(name) => WrappedRng::RngFile(rand::reader::ReaderRng::new(try!(io::File::open(&Path::new(name))))), Some(name) => WrappedRng::RngFile(rand::reader::ReaderRng::new(try!(io::File::open(&Path::new(name))))),
None => WrappedRng::RngDefault(rand::task_rng()), None => WrappedRng::RngDefault(rand::thread_rng()),
}; };
let mut len = lines.len(); let mut len = lines.len();
let max = if repeat { count } else { cmp::min(count, len) }; let max = if repeat { count } else { cmp::min(count, len) };

View file

@ -177,7 +177,7 @@ impl Splitter for ByteSplitter {
_ => crash!(1, "invalid number of bytes") _ => crash!(1, "invalid number of bytes")
}; };
let n = if suffix.is_alphabetic() { let n = if suffix.is_alphabetic() {
match String::from_chars(strategy_param.as_slice()).as_slice().parse::<uint>() { match strategy_param.as_slice().iter().map(|c| *c).collect::<String>().as_slice().parse::<uint>() {
Some(a) => a, Some(a) => a,
_ => crash!(1, "invalid number of bytes") _ => crash!(1, "invalid number of bytes")
} }

View file

@ -108,7 +108,7 @@ pub fn uumain(args: Vec<String>) -> int {
let sysv = matches.opt_present("sysv"); let sysv = matches.opt_present("sysv");
let files = if matches.free.is_empty() { let files = if matches.free.is_empty() {
Vec::from_elem(1, "-".to_string()) vec!["-".to_string()]
} else { } else {
matches.free matches.free
}; };

View file

@ -102,7 +102,7 @@ mod platform {
unsafe fn find_all_volumes() -> Vec<String> { unsafe fn find_all_volumes() -> Vec<String> {
match find_first_volume() { match find_first_volume() {
(first_volume, next_volume_handle) => { (first_volume, next_volume_handle) => {
let mut volumes = Vec::from_elem(1, first_volume); let mut volumes = vec![first_volume];
loop { loop {
let mut name: [libc::c_char; 260] = mem::uninitialized(); // MAX_PATH let mut name: [libc::c_char; 260] = mem::uninitialized(); // MAX_PATH
match FindNextVolumeA(next_volume_handle, match FindNextVolumeA(next_volume_handle,

View file

@ -1,7 +1,5 @@
#![crate_name = "tee"] #![crate_name = "tee"]
#![feature(phase)] #![feature(phase)]
#![feature(macro_rules)]
/* /*
* This file is part of the uutils coreutils package. * This file is part of the uutils coreutils package.
* *
@ -12,7 +10,7 @@
*/ */
extern crate getopts; extern crate getopts;
#[phase(plugin, link)] extern crate log; #[macro_use] extern crate log;
use std::io::{println, stdin, stdout, Append, File, Truncate, Write}; use std::io::{println, stdin, stdout, Append, File, Truncate, Write};
use std::io::{IoResult}; use std::io::{IoResult};
@ -143,7 +141,7 @@ impl Reader for NamedReader {
} }
} }
fn with_path<T>(path: &Path, cb: || -> IoResult<T>) -> IoResult<T> { fn with_path<F, T>(path: &Path, cb: F) -> IoResult<T> where F: Fn() -> IoResult<T> {
match cb() { match cb() {
Err(f) => { warn(format!("{}: {}", path.display(), f.to_string()).as_slice()); Err(f) } Err(f) => { warn(format!("{}: {}", path.display(), f.to_string()).as_slice()); Err(f) }
okay => okay okay => okay

View file

@ -17,6 +17,7 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::ffi::c_str_to_bytes;
use std::io::println; use std::io::println;
use std::io::stdio::stderr; use std::io::stdio::stderr;
use getopts::{optflag,getopts}; use getopts::{optflag,getopts};
@ -48,7 +49,14 @@ pub fn uumain(args: Vec<String>) -> int {
} }
}; };
let tty = unsafe { String::from_raw_buf(ttyname(libc::STDIN_FILENO) as *const u8) }; let tty = unsafe {
let ptr = ttyname(libc::STDIN_FILENO);
if !ptr.is_null() {
String::from_utf8_lossy(c_str_to_bytes(&ptr)).to_string()
} else {
"".to_string()
}
};
if !silent { if !silent {
if !tty.as_slice().chars().all(|c| c.is_whitespace()) { if !tty.as_slice().chars().all(|c| c.is_whitespace()) {

View file

@ -16,6 +16,7 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::ffi::c_str_to_bytes;
use std::mem::uninitialized; use std::mem::uninitialized;
use std::io::print; use std::io::print;
use c_types::utsname; use c_types::utsname;
@ -35,15 +36,19 @@ extern {
fn uname(uts: *mut utsname); fn uname(uts: *mut utsname);
} }
unsafe fn string_from_c_str(ptr: *const i8) -> String {
String::from_utf8_lossy(c_str_to_bytes(&ptr)).to_string()
}
unsafe fn getuname() -> utsrust { unsafe fn getuname() -> utsrust {
let mut uts: utsname = uninitialized(); let mut uts: utsname = uninitialized();
uname(&mut uts); uname(&mut uts);
utsrust { utsrust {
sysname: String::from_raw_buf(uts.sysname.as_ptr() as *const u8), sysname: string_from_c_str(uts.sysname.as_ptr() as *const i8),
nodename: String::from_raw_buf(uts.nodename.as_ptr() as *const u8), nodename: string_from_c_str(uts.nodename.as_ptr() as *const i8),
release: String::from_raw_buf(uts.release.as_ptr() as *const u8), release: string_from_c_str(uts.release.as_ptr() as *const i8),
version: String::from_raw_buf(uts.version.as_ptr() as *const u8), version: string_from_c_str(uts.version.as_ptr() as *const i8),
machine: String::from_raw_buf(uts.machine.as_ptr() as *const u8) machine: string_from_c_str(uts.machine.as_ptr() as *const i8)
} }
} }

View file

@ -17,6 +17,7 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::ffi::c_str_to_bytes;
use std::io::print; use std::io::print;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -107,7 +108,7 @@ fn exec(filename: &str) {
} }
if (*line).ut_type == USER_PROCESS { if (*line).ut_type == USER_PROCESS {
let user = String::from_raw_buf(mem::transmute(&(*line).ut_user)); let user = String::from_utf8_lossy(c_str_to_bytes(mem::transmute(&(*line).ut_user))).to_string();
users.push(user); users.push(user);
} }
} }