Convert more Pal methods to Result.

This commit is contained in:
4lDO2
2024-09-22 20:03:10 +02:00
parent 6e5959b3fa
commit 4b687c25d2
14 changed files with 330 additions and 348 deletions
+26 -9
View File
@@ -453,7 +453,10 @@ pub extern "C" fn gethostid() -> c_long {
#[no_mangle]
pub unsafe extern "C" fn gethostname(mut name: *mut c_char, mut len: size_t) -> c_int {
let mut uts = mem::MaybeUninit::<sys_utsname::utsname>::uninit();
let err = Sys::uname(uts.as_mut_ptr());
// TODO
let err = Sys::uname(uts.as_mut_ptr())
.map(|()| 0)
.or_minus_one_errno();
if err < 0 {
mem::forget(uts);
return err;
@@ -558,7 +561,7 @@ pub unsafe extern "C" fn lchown(path: *const c_char, owner: uid_t, group: gid_t)
pub unsafe extern "C" fn link(path1: *const c_char, path2: *const c_char) -> c_int {
let path1 = CStr::from_ptr(path1);
let path2 = CStr::from_ptr(path2);
Sys::link(path1, path2)
Sys::link(path1, path2).map(|()| 0).or_minus_one_errno()
}
#[no_mangle]
@@ -602,7 +605,7 @@ pub unsafe extern "C" fn lockf(fildes: c_int, function: c_int, size: off_t) -> c
#[no_mangle]
pub extern "C" fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t {
Sys::lseek(fildes, offset, whence)
Sys::lseek(fildes, offset, whence).or_minus_one_errno()
}
// #[no_mangle]
@@ -623,6 +626,8 @@ pub unsafe extern "C" fn pipe(fildes: *mut c_int) -> c_int {
#[no_mangle]
pub unsafe extern "C" fn pipe2(fildes: *mut c_int, flags: c_int) -> c_int {
Sys::pipe2(slice::from_raw_parts_mut(fildes, 2), flags)
.map(|()| 0)
.or_minus_one_errno()
}
#[no_mangle]
@@ -694,7 +699,7 @@ pub unsafe extern "C" fn readlink(
) -> ssize_t {
let path = CStr::from_ptr(path);
let buf = slice::from_raw_parts_mut(buf as *mut u8, bufsize as usize);
Sys::readlink(path, buf)
Sys::readlink(path, buf).or_minus_one_errno()
}
#[no_mangle]
@@ -706,16 +711,18 @@ pub unsafe extern "C" fn rmdir(path: *const c_char) -> c_int {
#[no_mangle]
pub extern "C" fn setgid(gid: gid_t) -> c_int {
Sys::setresgid(gid, gid, -1)
.map(|()| 0)
.or_minus_one_errno()
}
#[no_mangle]
pub unsafe extern "C" fn setgroups(size: size_t, list: *const gid_t) -> c_int {
Sys::setgroups(size, list)
Sys::setgroups(size, list).map(|()| 0).or_minus_one_errno()
}
#[no_mangle]
pub extern "C" fn setpgid(pid: pid_t, pgid: pid_t) -> c_int {
Sys::setpgid(pid, pgid)
Sys::setpgid(pid, pgid).map(|()| 0).or_minus_one_errno()
}
#[no_mangle]
@@ -726,29 +733,39 @@ pub extern "C" fn setpgrp() -> pid_t {
#[no_mangle]
pub extern "C" fn setregid(rgid: gid_t, egid: gid_t) -> c_int {
Sys::setresgid(rgid, egid, -1)
.map(|()| 0)
.or_minus_one_errno()
}
#[no_mangle]
pub extern "C" fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) -> c_int {
Sys::setresgid(rgid, egid, sgid)
.map(|()| 0)
.or_minus_one_errno()
}
#[no_mangle]
pub extern "C" fn setreuid(ruid: uid_t, euid: uid_t) -> c_int {
Sys::setresuid(ruid, euid, -1)
.map(|()| 0)
.or_minus_one_errno()
}
#[no_mangle]
pub extern "C" fn setsid() -> pid_t {
Sys::setsid()
Sys::setsid().map(|()| 0).or_minus_one_errno()
}
#[no_mangle]
pub extern "C" fn setuid(uid: uid_t) -> c_int {
Sys::setresuid(uid, uid, -1)
.map(|()| 0)
.or_minus_one_errno()
}
#[no_mangle]
pub extern "C" fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) -> c_int {
Sys::setresuid(ruid, euid, suid)
.map(|()| 0)
.or_minus_one_errno()
}
#[no_mangle]
@@ -782,7 +799,7 @@ pub extern "C" fn swab(src: *const c_void, dest: *mut c_void, nbytes: ssize_t) {
pub unsafe extern "C" fn symlink(path1: *const c_char, path2: *const c_char) -> c_int {
let path1 = CStr::from_ptr(path1);
let path2 = CStr::from_ptr(path2);
Sys::symlink(path1, path2)
Sys::symlink(path1, path2).map(|()| 0).or_minus_one_errno()
}
#[no_mangle]
@@ -840,7 +857,7 @@ pub extern "C" fn ttyname_r(fildes: c_int, name: *mut c_char, namesize: size_t)
return errno::ERANGE;
}
let len = Sys::fpath(fildes, &mut name[..namesize - 1]);
let len = Sys::fpath(fildes, &mut name[..namesize - 1]).or_minus_one_errno();
if len < 0 {
return -platform::ERRNO.get();
}