From c911facca6147bde9dba1b452eff89d00279eba4 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jeremy@system76.com> Date: Mon, 27 Aug 2018 08:33:12 -0600 Subject: [PATCH] Make pal functions take cstr --- build.rs | 1 + src/header/dirent/mod.rs | 2 ++ src/header/fcntl/mod.rs | 2 ++ src/header/pwd/mod.rs | 3 ++- src/header/stdio/mod.rs | 9 ++++++- src/header/stdlib/mod.rs | 5 +++- src/header/sys_stat/mod.rs | 13 +++++----- src/header/sys_time/mod.rs | 2 ++ src/header/unistd/mod.rs | 9 +++++++ src/header/utime/mod.rs | 2 ++ src/platform/linux/mod.rs | 53 +++++++++++++++++++------------------- src/platform/pal/mod.rs | 27 +++++++++---------- src/platform/rawfile.rs | 3 ++- src/platform/redox/mod.rs | 30 ++++++++++----------- 14 files changed, 96 insertions(+), 65 deletions(-) diff --git a/build.rs b/build.rs index 8f61a6d4b..4ee52afdf 100644 --- a/build.rs +++ b/build.rs @@ -11,6 +11,7 @@ fn main() { .flag("-I") .flag(&format!("{}/include", crate_dir)) .flag("-fno-stack-protector") + .flag("-Wno-expansion-to-defined") .file("src/c/dlmalloc.c") .file("src/c/fcntl.c") .file("src/c/stack_chk.c") diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs index 09ba4a7f9..478e90246 100644 --- a/src/header/dirent/mod.rs +++ b/src/header/dirent/mod.rs @@ -3,6 +3,7 @@ use alloc::boxed::Box; use core::{mem, ptr}; +use c_str::CStr; use header::{errno, fcntl, unistd}; use platform; use platform::types::*; @@ -35,6 +36,7 @@ pub struct dirent { #[no_mangle] pub extern "C" fn opendir(path: *const c_char) -> *mut DIR { + let path = unsafe { CStr::from_ptr(path) }; let fd = Sys::open( path, fcntl::O_RDONLY | fcntl::O_DIRECTORY | fcntl::O_CLOEXEC, diff --git a/src/header/fcntl/mod.rs b/src/header/fcntl/mod.rs index a22d0eb52..07a88647c 100644 --- a/src/header/fcntl/mod.rs +++ b/src/header/fcntl/mod.rs @@ -1,5 +1,6 @@ //! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html +use c_str::CStr; use platform::types::*; use platform::{Pal, Sys}; @@ -40,5 +41,6 @@ pub extern "C" fn sys_fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { #[no_mangle] pub extern "C" fn sys_open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::open(path, oflag, mode) } diff --git a/src/header/pwd/mod.rs b/src/header/pwd/mod.rs index 139acc389..d719cecba 100644 --- a/src/header/pwd/mod.rs +++ b/src/header/pwd/mod.rs @@ -3,6 +3,7 @@ use alloc::vec::Vec; use core::ptr; +use c_str::CStr; use header::{errno, fcntl}; use platform; use platform::types::*; @@ -47,7 +48,7 @@ where F: FnMut(&[&[u8]]) -> bool, { let file = match RawFile::open( - "/etc/passwd\0".as_ptr() as *const c_char, + CStr::from_bytes_with_nul(b"/etc/passwd\0").unwrap(), fcntl::O_RDONLY, 0, ) { diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index ca4bdc515..e4e0e8d9e 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -7,6 +7,7 @@ use core::sync::atomic::{AtomicBool, Ordering}; use core::{ptr, str}; use va_list::VaList as va_list; +use c_str::CStr; use header::errno::{self, STR_ERROR}; use header::fcntl; use header::stdlib::mkstemp; @@ -814,6 +815,7 @@ pub extern "C" fn putw(w: c_int, stream: &mut FILE) -> c_int { /// Delete file or directory `path` #[no_mangle] pub extern "C" fn remove(path: *const c_char) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; let r = Sys::unlink(path); if r == -errno::EISDIR { Sys::rmdir(path) @@ -824,6 +826,8 @@ pub extern "C" fn remove(path: *const c_char) -> c_int { #[no_mangle] pub extern "C" fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int { + let oldpath = unsafe { CStr::from_ptr(oldpath) }; + let newpath = unsafe { CStr::from_ptr(newpath) }; Sys::rename(oldpath, newpath) } @@ -894,7 +898,10 @@ pub extern "C" fn tmpfile() -> *mut FILE { } let fp = fdopen(fd, b"w+".as_ptr() as *const i8); - Sys::unlink(file_name); + { + let file_name = unsafe { CStr::from_ptr(file_name) }; + Sys::unlink(file_name); + } if fp == ptr::null_mut() { Sys::close(fd); diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index a11a06b4e..9116eb7a4 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -6,6 +6,7 @@ use rand::prng::XorShiftRng; use rand::rngs::JitterRng; use rand::{Rng, SeedableRng}; +use c_str::CStr; use header::errno::*; use header::fcntl::*; use header::string::*; @@ -390,7 +391,7 @@ fn inner_mktemp<T, F>(name: *mut c_char, suffix_len: c_int, mut attempt: F) -> O where F: FnMut() -> Option<T>, { - let len = unsafe { strlen(name) } as c_int; + let len = unsafe { strlen(name) as c_int }; if len < 6 || suffix_len > len - 6 { unsafe { platform::errno = errno::EINVAL }; @@ -432,6 +433,7 @@ where #[no_mangle] pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { if inner_mktemp(name, 0, || unsafe { + let name = unsafe { CStr::from_ptr(name) }; let ret = if Sys::access(name, 0) != 0 && platform::errno == ENOENT { Some(()) } else { @@ -459,6 +461,7 @@ pub extern "C" fn mkostemps(name: *mut c_char, suffix_len: c_int, mut flags: c_i flags |= O_RDWR | O_CREAT | O_EXCL; inner_mktemp(name, suffix_len, || { + let name = unsafe { CStr::from_ptr(name) }; let fd = Sys::open(name, flags, 0600); if fd >= 0 { diff --git a/src/header/sys_stat/mod.rs b/src/header/sys_stat/mod.rs index 8490a3126..1bd6c005d 100644 --- a/src/header/sys_stat/mod.rs +++ b/src/header/sys_stat/mod.rs @@ -1,5 +1,6 @@ //! stat implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html +use c_str::CStr; use header::fcntl::{O_NOFOLLOW, O_PATH}; use platform; use platform::types::*; @@ -58,6 +59,7 @@ pub struct stat { #[no_mangle] pub extern "C" fn chmod(path: *const c_char, mode: mode_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::chmod(path, mode) } @@ -83,6 +85,7 @@ pub extern "C" fn futimens(fd: c_int, times: *const timespec) -> c_int { #[no_mangle] pub extern "C" fn lstat(path: *const c_char, buf: *mut platform::types::stat) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; let fd = Sys::open(path, O_PATH | O_NOFOLLOW, 0); if fd < 0 { return -1; @@ -97,11 +100,13 @@ pub extern "C" fn lstat(path: *const c_char, buf: *mut platform::types::stat) -> #[no_mangle] pub extern "C" fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::mkdir(path, mode) } #[no_mangle] pub extern "C" fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::mkfifo(path, mode) } @@ -112,6 +117,7 @@ pub extern "C" fn mknod(path: *const c_char, mode: mode_t, dev: dev_t) -> c_int #[no_mangle] pub extern "C" fn stat(file: *const c_char, buf: *mut platform::types::stat) -> c_int { + let file = unsafe { CStr::from_ptr(file) }; let fd = Sys::open(file, O_PATH, 0); if fd < 0 { return -1; @@ -128,10 +134,3 @@ pub extern "C" fn stat(file: *const c_char, buf: *mut platform::types::stat) -> pub extern "C" fn umask(mask: mode_t) -> mode_t { Sys::umask(mask) } - -/* -#[no_mangle] -pub extern "C" fn func(args) -> c_int { - unimplemented!(); -} -*/ diff --git a/src/header/sys_time/mod.rs b/src/header/sys_time/mod.rs index 13c67d9d4..dc50a4ce8 100644 --- a/src/header/sys_time/mod.rs +++ b/src/header/sys_time/mod.rs @@ -1,5 +1,6 @@ //! sys/time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/systime.h.html +use c_str::CStr; use platform; use platform::types::*; use platform::{Pal, Sys}; @@ -71,6 +72,7 @@ pub extern "C" fn select( #[no_mangle] pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c_int { + let path = CStr::from_ptr(path); let times_spec = [ timespec { tv_sec: (*times.offset(0)).tv_sec, diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 0f426a730..5a7e8b1cd 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -2,6 +2,7 @@ use core::{ptr, slice}; +use c_str::CStr; use header::sys_time; use platform; use platform::types::*; @@ -42,6 +43,7 @@ pub extern "C" fn _exit(status: c_int) { #[no_mangle] pub extern "C" fn access(path: *const c_char, mode: c_int) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::access(path, mode) } @@ -69,6 +71,7 @@ pub extern "C" fn alarm(seconds: c_uint) -> c_uint { #[no_mangle] pub extern "C" fn chdir(path: *const c_char) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::chdir(path) } @@ -79,6 +82,7 @@ pub extern "C" fn chroot(path: *const c_char) -> c_int { #[no_mangle] pub extern "C" fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::chown(path, owner, group) } @@ -142,6 +146,7 @@ pub unsafe extern "C" fn execve( argv: *const *mut c_char, envp: *const *mut c_char, ) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::execve(path, argv, envp) } @@ -313,6 +318,8 @@ pub extern "C" fn lchown(path: *const c_char, owner: uid_t, group: gid_t) -> c_i #[no_mangle] pub extern "C" fn link(path1: *const c_char, path2: *const c_char) -> c_int { + let path1 = unsafe { CStr::from_ptr(path1) }; + let path2 = unsafe { CStr::from_ptr(path2) }; Sys::link(path1, path2) } @@ -379,6 +386,7 @@ pub extern "C" fn readlink(path: *const c_char, buf: *mut c_char, bufsize: size_ #[no_mangle] pub extern "C" fn rmdir(path: *const c_char) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::rmdir(path) } @@ -500,6 +508,7 @@ pub extern "C" fn ualarm(value: useconds_t, interval: useconds_t) -> useconds_t #[no_mangle] pub extern "C" fn unlink(path: *const c_char) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::unlink(path) } diff --git a/src/header/utime/mod.rs b/src/header/utime/mod.rs index dd891aa6e..8007744a3 100644 --- a/src/header/utime/mod.rs +++ b/src/header/utime/mod.rs @@ -1,5 +1,6 @@ //! utime implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/utime.h.html +use c_str::CStr; use platform::types::*; use platform::{Pal, Sys}; @@ -12,6 +13,7 @@ pub struct utimbuf { #[no_mangle] pub unsafe extern "C" fn utime(filename: *const c_char, times: *const utimbuf) -> c_int { + let filename = CStr::from_ptr(filename); let times_spec = [ timespec { tv_sec: (*times).actime, diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 80061b698..1f9884aaa 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -1,6 +1,7 @@ use core::fmt::Write; use core::{mem, ptr}; +use c_str::CStr; use super::types::*; use super::{errno, FileWriter, Pal}; @@ -42,24 +43,24 @@ impl Pal for Sys { -1 } - fn access(path: *const c_char, mode: c_int) -> c_int { - e(unsafe { syscall!(ACCESS, path, mode) }) as c_int + fn access(path: &CStr, mode: c_int) -> c_int { + e(unsafe { syscall!(ACCESS, path.as_ptr(), mode) }) as c_int } fn brk(addr: *mut c_void) -> *mut c_void { unsafe { syscall!(BRK, addr) as *mut c_void } } - fn chdir(path: *const c_char) -> c_int { - e(unsafe { syscall!(CHDIR, path) }) as c_int + fn chdir(path: &CStr) -> c_int { + e(unsafe { syscall!(CHDIR, path.as_ptr()) }) as c_int } - fn chmod(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(FCHMODAT, AT_FDCWD, path, mode, 0) }) as c_int + fn chmod(path: &CStr, mode: mode_t) -> c_int { + e(unsafe { syscall!(FCHMODAT, AT_FDCWD, path.as_ptr(), mode, 0) }) as c_int } - fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { - e(unsafe { syscall!(FCHOWNAT, AT_FDCWD, path, owner as u32, group as u32) }) as c_int + fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int { + e(unsafe { syscall!(FCHOWNAT, AT_FDCWD, path.as_ptr(), owner as u32, group as u32) }) as c_int } fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { @@ -79,11 +80,11 @@ impl Pal for Sys { } unsafe fn execve( - path: *const c_char, + path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char, ) -> c_int { - e(syscall!(EXECVE, path, argv, envp)) as c_int + e(syscall!(EXECVE, path.as_ptr(), argv, envp)) as c_int } fn exit(status: c_int) -> ! { @@ -134,8 +135,8 @@ impl Pal for Sys { e(unsafe { syscall!(UTIMENSAT, fd, ptr::null::<c_char>(), times, 0) }) as c_int } - fn utimens(path: *const c_char, times: *const timespec) -> c_int { - e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path, times, 0) }) as c_int + fn utimens(path: &CStr, times: *const timespec) -> c_int { + e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path.as_ptr(), times, 0) }) as c_int } fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char { @@ -228,20 +229,20 @@ impl Pal for Sys { (Self::ioctl(fd, TIOCGWINSZ, &mut winsize as *mut _ as *mut c_void) == 0) as c_int } - fn link(path1: *const c_char, path2: *const c_char) -> c_int { - e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int + fn link(path1: &CStr, path2: &CStr) -> c_int { + e(unsafe { syscall!(LINKAT, AT_FDCWD, path1.as_ptr(), AT_FDCWD, path2.as_ptr(), 0) }) as c_int } fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int + fn mkdir(path: &CStr, mode: mode_t) -> c_int { + e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path.as_ptr(), mode) }) as c_int } - fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(MKNODAT, AT_FDCWD, path, mode, 0) }) as c_int + fn mkfifo(path: &CStr, mode: mode_t) -> c_int { + e(unsafe { syscall!(MKNODAT, AT_FDCWD, path.as_ptr(), mode, 0) }) as c_int } unsafe fn mmap( @@ -263,8 +264,8 @@ impl Pal for Sys { e(unsafe { syscall!(NANOSLEEP, rqtp, rmtp) }) as c_int } - fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { - e(unsafe { syscall!(OPENAT, AT_FDCWD, path, oflag, mode) }) as c_int + fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int { + e(unsafe { syscall!(OPENAT, AT_FDCWD, path.as_ptr(), oflag, mode) }) as c_int } fn pipe(fildes: &mut [c_int]) -> c_int { @@ -275,12 +276,12 @@ impl Pal for Sys { e(unsafe { syscall!(READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t } - fn rename(old: *const c_char, new: *const c_char) -> c_int { - e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old, AT_FDCWD, new) }) as c_int + fn rename(old: &CStr, new: &CStr) -> c_int { + e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old.as_ptr(), AT_FDCWD, new.as_ptr()) }) as c_int } - fn rmdir(path: *const c_char) -> c_int { - e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, AT_REMOVEDIR) }) as c_int + fn rmdir(path: &CStr) -> c_int { + e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path.as_ptr(), AT_REMOVEDIR) }) as c_int } fn select( @@ -336,8 +337,8 @@ impl Pal for Sys { e(unsafe { syscall!(UNAME, utsname, 0) }) as c_int } - fn unlink(path: *const c_char) -> c_int { - e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, 0) }) as c_int + fn unlink(path: &CStr) -> c_int { + e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path.as_ptr(), 0) }) as c_int } fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { diff --git a/src/platform/pal/mod.rs b/src/platform/pal/mod.rs index b1da6f24d..3a1dec48a 100644 --- a/src/platform/pal/mod.rs +++ b/src/platform/pal/mod.rs @@ -1,5 +1,6 @@ use core::ptr; +use c_str::CStr; use super::types::*; pub use self::signal::PalSignal; @@ -11,21 +12,21 @@ mod socket; pub trait Pal { fn no_pal(name: &str) -> c_int; - fn access(path: *const c_char, mode: c_int) -> c_int { + fn access(path: &CStr, mode: c_int) -> c_int { Self::no_pal("access") } fn brk(addr: *mut c_void) -> *mut c_void; - fn chdir(path: *const c_char) -> c_int { + fn chdir(path: &CStr) -> c_int { Self::no_pal("chdir") } - fn chmod(path: *const c_char, mode: mode_t) -> c_int { + fn chmod(path: &CStr, mode: mode_t) -> c_int { Self::no_pal("chmod") } - fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int { Self::no_pal("chown") } @@ -46,7 +47,7 @@ pub trait Pal { } unsafe fn execve( - path: *const c_char, + path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char, ) -> c_int { @@ -95,7 +96,7 @@ pub trait Pal { Self::no_pal("futimens") } - fn utimens(path: *const c_char, times: *const timespec) -> c_int { + fn utimens(path: &CStr, times: *const timespec) -> c_int { Self::no_pal("utimens") } @@ -160,7 +161,7 @@ pub trait Pal { Self::no_pal("isatty") } - fn link(path1: *const c_char, path2: *const c_char) -> c_int { + fn link(path1: &CStr, path2: &CStr) -> c_int { Self::no_pal("link") } @@ -168,11 +169,11 @@ pub trait Pal { Self::no_pal("lseek") as off_t } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + fn mkdir(path: &CStr, mode: mode_t) -> c_int { Self::no_pal("mkdir") } - fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + fn mkfifo(path: &CStr, mode: mode_t) -> c_int { Self::no_pal("mkfifo") } @@ -195,7 +196,7 @@ pub trait Pal { Self::no_pal("nanosleep") } - fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int { Self::no_pal("open") } @@ -207,11 +208,11 @@ pub trait Pal { Self::no_pal("read") as ssize_t } - fn rename(old: *const c_char, new: *const c_char) -> c_int { + fn rename(old: &CStr, new: &CStr) -> c_int { Self::no_pal("rename") } - fn rmdir(path: *const c_char) -> c_int { + fn rmdir(path: &CStr) -> c_int { Self::no_pal("rmdir") } @@ -262,7 +263,7 @@ pub trait Pal { Self::no_pal("uname") } - fn unlink(path: *const c_char) -> c_int { + fn unlink(path: &CStr) -> c_int { Self::no_pal("unlink") } diff --git a/src/platform/rawfile.rs b/src/platform/rawfile.rs index 4686ce8d0..e111338aa 100644 --- a/src/platform/rawfile.rs +++ b/src/platform/rawfile.rs @@ -1,11 +1,12 @@ use core::ops::Deref; +use c_str::CStr; use super::{types::*, Pal, Sys}; pub struct RawFile(c_int); impl RawFile { - pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> Result<RawFile, ()> { + pub fn open(path: &CStr, oflag: c_int, mode: mode_t) -> Result<RawFile, ()> { match Sys::open(path, oflag, mode) { -1 => Err(()), n => Ok(RawFile(n)), diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 02bb24e1e..8fabf0617 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -50,7 +50,7 @@ impl Pal for Sys { -1 } - fn access(path: *const c_char, mode: c_int) -> c_int { + fn access(path: &CStr, mode: c_int) -> c_int { let fd = match RawFile::open(path, 0, 0) { Ok(fd) => fd, Err(_) => return -1, @@ -100,12 +100,12 @@ impl Pal for Sys { unsafe { syscall::brk(addr as usize).unwrap_or(0) as *mut c_void } } - fn chdir(path: *const c_char) -> c_int { + fn chdir(path: &CStr) -> c_int { let path = unsafe { c_str(path) }; e(syscall::chdir(path)) as c_int } - fn chmod(path: *const c_char, mode: mode_t) -> c_int { + fn chmod(path: &CStr, mode: mode_t) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, @@ -117,7 +117,7 @@ impl Pal for Sys { } } - fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, @@ -161,7 +161,7 @@ impl Pal for Sys { } unsafe fn execve( - path: *const c_char, + path: &CStr, mut argv: *const *mut c_char, mut envp: *const *mut c_char, ) -> c_int { @@ -290,7 +290,7 @@ impl Pal for Sys { e(syscall::futimens(fd as usize, ×)) as c_int } - fn utimens(path: *const c_char, times: *const timespec) -> c_int { + fn utimens(path: &CStr, times: *const timespec) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_STAT) { Err(err) => e(Err(err)) as c_int, @@ -443,7 +443,7 @@ impl Pal for Sys { .unwrap_or(0) } - fn link(path1: *const c_char, path2: *const c_char) -> c_int { + fn link(path1: &CStr, path2: &CStr) -> c_int { let path1 = unsafe { c_str(path1) }; let path2 = unsafe { c_str(path2) }; e(unsafe { syscall::link(path1.as_ptr(), path2.as_ptr()) }) as c_int @@ -457,7 +457,7 @@ impl Pal for Sys { )) as off_t } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + fn mkdir(path: &CStr, mode: mode_t) -> c_int { let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777; let path = unsafe { c_str(path) }; match syscall::open(path, flags) { @@ -469,7 +469,7 @@ impl Pal for Sys { } } - fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + fn mkfifo(path: &CStr, mode: mode_t) -> c_int { let flags = O_CREAT | MODE_FIFO as usize | mode as usize & 0o777; let path = unsafe { c_str(path) }; match syscall::open(path, flags) { @@ -540,7 +540,7 @@ impl Pal for Sys { } } - fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int { let path = unsafe { c_str(path) }; e(syscall::open(path, (oflag as usize) | (mode as usize))) as c_int } @@ -557,7 +557,7 @@ impl Pal for Sys { e(syscall::read(fd as usize, buf)) as ssize_t } - fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int { + fn rename(oldpath: &CStr, newpath: &CStr) -> c_int { let (oldpath, newpath) = unsafe { (c_str(oldpath), c_str(newpath)) }; match syscall::open(oldpath, O_WRONLY) { Ok(fd) => { @@ -569,7 +569,7 @@ impl Pal for Sys { } } - fn rmdir(path: *const c_char) -> c_int { + fn rmdir(path: &CStr) -> c_int { let path = unsafe { c_str(path) }; e(syscall::rmdir(path)) as c_int } @@ -590,7 +590,7 @@ impl Pal for Sys { unsafe { (*set).fds_bits[fd / (8 * mem::size_of::<c_ulong>())] & mask == mask } } - let event_file = match RawFile::open("event:\0".as_ptr() as *const c_char, 0, 0) { + let event_file = match RawFile::open("event:\0".as_ptr() as &CStr, 0, 0) { Ok(file) => file, Err(_) => return -1, }; @@ -632,7 +632,7 @@ impl Pal for Sys { None } else { let timeout_file = match RawFile::open( - format!("time:{}\0", syscall::CLOCK_MONOTONIC).as_ptr() as *const c_char, + format!("time:{}\0", syscall::CLOCK_MONOTONIC).as_ptr() as &CStr, 0, 0, ) { @@ -725,7 +725,7 @@ impl Pal for Sys { 0 } - fn unlink(path: *const c_char) -> c_int { + fn unlink(path: &CStr) -> c_int { let path = unsafe { c_str(path) }; e(syscall::unlink(path)) as c_int } -- GitLab