diff --git a/src/chmod/chmod.rs b/src/chmod/chmod.rs index 8680eb635..fb4179282 100644 --- a/src/chmod/chmod.rs +++ b/src/chmod/chmod.rs @@ -183,7 +183,7 @@ fn chmod(files: Vec, changes: bool, quiet: bool, verbose: bool, preserve } fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option, 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 { diff --git a/src/chroot/chroot.rs b/src/chroot/chroot.rs index de5b5d083..72e590841 100644 --- a/src/chroot/chroot.rs +++ b/src/chroot/chroot.rs @@ -95,8 +95,8 @@ pub fn uumain(args: Vec) -> 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()) diff --git a/src/common/c_types.rs b/src/common/c_types.rs index a84142ff8..32db00093 100644 --- a/src/common/c_types.rs +++ b/src/common/c_types.rs @@ -133,7 +133,7 @@ pub fn get_pw_from_args(free: &Vec) -> Option { // 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 { 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) } }; diff --git a/src/mkfifo/mkfifo.rs b/src/mkfifo/mkfifo.rs index 7695fb520..8a2eb0fe2 100644 --- a/src/mkfifo/mkfifo.rs +++ b/src/mkfifo/mkfifo.rs @@ -68,7 +68,7 @@ pub fn uumain(args: Vec) -> 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; diff --git a/src/nice/nice.rs b/src/nice/nice.rs index 1f3dd17b6..4e67bb320 100644 --- a/src/nice/nice.rs +++ b/src/nice/nice.rs @@ -102,7 +102,7 @@ pub fn uumain(args: Vec) -> i32 { show_warning!("{}", IoError::last_error()); } - let cstrs : Vec = matches.free.iter().map(|x| CString::from_slice(x.as_bytes())).collect(); + let cstrs : Vec = 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()); } diff --git a/src/nohup/nohup.rs b/src/nohup/nohup.rs index 06ced318a..be03ce704 100644 --- a/src/nohup/nohup.rs +++ b/src/nohup/nohup.rs @@ -69,7 +69,7 @@ pub fn uumain(args: Vec) -> i32 { if unsafe { _vprocmgr_detach_from_console(0) } != std::ptr::null() { crash!(2, "Cannot detach from console")}; - let cstrs : Vec = opts.free.iter().map(|x| CString::from_slice(x.as_bytes())).collect(); + let cstrs : Vec = 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())} diff --git a/src/test/test.rs b/src/test/test.rs index f5baf4111..b484630bb 100644 --- a/src/test/test.rs +++ b/src/test/test.rs @@ -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 { diff --git a/src/uptime/uptime.rs b/src/uptime/uptime.rs index 694c7ddc0..aecfb2dc5 100644 --- a/src/uptime/uptime.rs +++ b/src/uptime/uptime.rs @@ -108,7 +108,7 @@ fn print_loadavg() { #[cfg(unix)] fn process_utmpx() -> (Option, usize) { unsafe { - utmpxname(CString::from_slice(DEFAULT_FILE.as_bytes()).as_ptr()); + utmpxname(CString::new(DEFAULT_FILE).unwrap().as_ptr()); } let mut nusers = 0; diff --git a/src/users/users.rs b/src/users/users.rs index 92d1e6de9..0001628d7 100644 --- a/src/users/users.rs +++ b/src/users/users.rs @@ -91,7 +91,7 @@ pub fn uumain(args: Vec) -> 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!();