1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 21:17:46 +00:00

CString::from_slice -> CString::new

This commit is contained in:
Michael Gehring 2015-02-22 13:22:51 +01:00
parent 3993a2bf90
commit eb6594cc91
9 changed files with 12 additions and 12 deletions

View file

@ -183,7 +183,7 @@ fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve
}
fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), i32> {
let path = CString::from_slice(name.as_bytes());
let path = CString::new(name).unwrap();
match fmode {
Some(mode) => {
if unsafe { libc::chmod(path.as_ptr(), mode) } == 0 {

View file

@ -95,8 +95,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
set_context(&newroot, &opts);
unsafe {
let executable = CString::from_slice(command[0].as_bytes()).as_bytes_with_nul().as_ptr();
let mut command_parts: Vec<*const u8> = command.iter().map(|x| CString::from_slice(x.as_bytes()).as_bytes_with_nul().as_ptr()).collect();
let executable = CString::new(command[0]).unwrap().as_bytes_with_nul().as_ptr();
let mut command_parts: Vec<*const u8> = command.iter().map(|x| CString::new(x.as_bytes()).unwrap().as_bytes_with_nul().as_ptr()).collect();
command_parts.push(std::ptr::null());
execvp(executable as *const libc::c_char, command_parts.as_ptr() as *mut *const libc::c_char) as i32
}
@ -131,7 +131,7 @@ fn enter_chroot(root: &Path) {
let root_str = root.display();
std::os::change_dir(root).unwrap();
let err = unsafe {
chroot(CString::from_slice(b".").as_bytes_with_nul().as_ptr() as *const libc::c_char)
chroot(CString::new(b".").unwrap().as_bytes_with_nul().as_ptr() as *const libc::c_char)
};
if err != 0 {
crash!(1, "cannot chroot to {}: {}", root_str, strerror(err).as_slice())

View file

@ -133,7 +133,7 @@ pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
// Passed the username as a string
} else {
let pw_pointer = unsafe {
let cstr = CString::from_slice(username.as_bytes());
let cstr = CString::new(username).unwrap();
getpwnam(cstr.as_bytes_with_nul().as_ptr() as *const i8)
};
if !pw_pointer.is_null() {
@ -152,7 +152,7 @@ pub fn get_group(groupname: &str) -> Option<c_group> {
unsafe { getgrgid(groupname.parse().unwrap()) }
} else {
unsafe {
let cstr = CString::from_slice(groupname.as_bytes());
let cstr = CString::new(groupname).unwrap();
getgrnam(cstr.as_bytes_with_nul().as_ptr() as *const c_char)
}
};

View file

@ -68,7 +68,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
let mut exit_status = 0;
for f in matches.free.iter() {
let err = unsafe { mkfifo(CString::from_slice(f.as_bytes()).as_ptr(), mode) };
let err = unsafe { mkfifo(CString::new(f.as_bytes()).unwrap().as_ptr(), mode) };
if err == -1 {
show_error!("creating '{}': {}", f, os::error_string(os::errno()));
exit_status = 1;

View file

@ -102,7 +102,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
show_warning!("{}", IoError::last_error());
}
let cstrs : Vec<CString> = matches.free.iter().map(|x| CString::from_slice(x.as_bytes())).collect();
let cstrs : Vec<CString> = matches.free.iter().map(|x| CString::new(x.as_bytes()).unwrap()).collect();
let mut args : Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
args.push(0 as *const c_char);
unsafe { execvp(args[0], args.as_mut_ptr()); }

View file

@ -69,7 +69,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
if unsafe { _vprocmgr_detach_from_console(0) } != std::ptr::null() { crash!(2, "Cannot detach from console")};
let cstrs : Vec<CString> = opts.free.iter().map(|x| CString::from_slice(x.as_bytes())).collect();
let cstrs : Vec<CString> = opts.free.iter().map(|x| CString::new(x.as_bytes()).unwrap()).collect();
let mut args : Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
args.push(std::ptr::null());
unsafe { execvp(args[0], args.as_mut_ptr())}

View file

@ -348,7 +348,7 @@ fn path(path: &[u8], cond: PathCondition) -> bool {
}
};
let path = CString::from_slice(path);
let path = CString::new(path).unwrap();
let mut stat = unsafe { std::mem::zeroed() };
if cond == PathCondition::SymLink {
if unsafe { lstat(path.as_ptr(), &mut stat) } == 0 {

View file

@ -108,7 +108,7 @@ fn print_loadavg() {
#[cfg(unix)]
fn process_utmpx() -> (Option<time_t>, usize) {
unsafe {
utmpxname(CString::from_slice(DEFAULT_FILE.as_bytes()).as_ptr());
utmpxname(CString::new(DEFAULT_FILE).unwrap().as_ptr());
}
let mut nusers = 0;

View file

@ -91,7 +91,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
fn exec(filename: &str) {
unsafe {
utmpxname(CString::from_slice(filename.as_bytes()).as_ptr());
utmpxname(CString::new(filename).unwrap().as_ptr());
}
let mut users = vec!();