From 56735753548fa2284e09ed0749589c7d35db189e Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 6 Jul 2025 12:54:39 -0600 Subject: [PATCH] Revert "Merge branch 'rustifying' into 'master'" This reverts merge request !663 --- src/header/stdlib/mod.rs | 10 +++++++++- src/header/sys_stat/mod.rs | 32 ++++++++++++++++++++++---------- src/header/sys_statvfs/mod.rs | 16 +++++++++++----- src/header/unistd/mod.rs | 16 +++++++++++----- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index 1b7b58df23..1da1a154fa 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -791,12 +791,20 @@ pub unsafe extern "C" fn mkostemps( suffix_len: c_int, mut flags: c_int, ) -> c_int { + // TODO: Rustify impl + flags &= !O_ACCMODE; flags |= O_RDWR | O_CREAT | O_EXCL; inner_mktemp(name, suffix_len, || { let name = CStr::from_ptr(name); - Sys::open(name, flags, 0o600).ok() + let fd = Sys::open(name, flags, 0o600).or_minus_one_errno(); + + if fd >= 0 { + Some(fd) + } else { + None + } }) .unwrap_or(-1) } diff --git a/src/header/sys_stat/mod.rs b/src/header/sys_stat/mod.rs index ef5866919a..5b75c31a30 100644 --- a/src/header/sys_stat/mod.rs +++ b/src/header/sys_stat/mod.rs @@ -94,12 +94,18 @@ pub unsafe extern "C" fn futimens(fd: c_int, times: *const timespec) -> c_int { #[no_mangle] pub unsafe extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int { let path = CStr::from_ptr(path); + // TODO: Rustify + let fd = Sys::open(path, O_PATH | O_NOFOLLOW, 0).or_minus_one_errno(); + if fd < 0 { + return -1; + } - Sys::open(path, O_PATH | O_NOFOLLOW, 0).map_or(-1, |fd| { - let res = Sys::fstat(fd, buf).map(|()| 0).or_minus_one_errno(); - Sys::close(fd); - res - }) + // TODO: Rustify + let res = Sys::fstat(fd, buf).map(|()| 0).or_minus_one_errno(); + + Sys::close(fd); + + res } #[no_mangle] @@ -136,12 +142,18 @@ pub unsafe extern "C" fn mknodat( #[no_mangle] pub unsafe extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int { let file = CStr::from_ptr(file); + // TODO: Rustify + let fd = Sys::open(file, O_PATH, 0).or_minus_one_errno(); + if fd < 0 { + return -1; + } - Sys::open(file, O_PATH, 0).map_or(-1, |fd| { - let res = Sys::fstat(fd, buf).map(|()| 0).or_minus_one_errno(); - Sys::close(fd); - res - }) + // TODO: Rustify + let res = Sys::fstat(fd, buf).map(|()| 0).or_minus_one_errno(); + + Sys::close(fd); + + res } #[no_mangle] diff --git a/src/header/sys_statvfs/mod.rs b/src/header/sys_statvfs/mod.rs index 70a76e3ea8..306e0436bf 100644 --- a/src/header/sys_statvfs/mod.rs +++ b/src/header/sys_statvfs/mod.rs @@ -34,9 +34,15 @@ pub unsafe extern "C" fn fstatvfs(fildes: c_int, buf: *mut statvfs) -> c_int { #[no_mangle] pub unsafe extern "C" fn statvfs(file: *const c_char, buf: *mut statvfs) -> c_int { let file = CStr::from_ptr(file); - Sys::open(file, O_PATH, 0).map_or(-1, |fd| { - let res = Sys::fstatvfs(fd, buf).map(|()| 0).or_minus_one_errno(); - Sys::close(fd); - res - }) + // TODO: Rustify + let fd = Sys::open(file, O_PATH, 0).or_minus_one_errno(); + if fd < 0 { + return -1; + } + + let res = Sys::fstatvfs(fd, buf).map(|()| 0).or_minus_one_errno(); + + Sys::close(fd); + + res } diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 998c84094b..26468bccf7 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -982,11 +982,17 @@ pub extern "C" fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> c_int { #[no_mangle] pub unsafe extern "C" fn truncate(path: *const c_char, length: off_t) -> c_int { let file = unsafe { CStr::from_ptr(path) }; - Sys::open(file, fcntl::O_WRONLY, 0).map_or(-1, |fd| { - let res = ftruncate(fd, length); - Sys::close(fd); - res - }) + // TODO: Rustify + let fd = Sys::open(file, fcntl::O_WRONLY, 0).or_minus_one_errno(); + if fd < 0 { + return -1; + } + + let res = ftruncate(fd, length); + + Sys::close(fd); + + res } /// See .