Remove redundant code and impl them in terms of *at functions

The following functions were replaced with their *at variants or
similar:
- lstat -> lstat -> fstatat
- stat -> stat -> fstatat
- fstat -> fstatat
- fchmod -> fchmodat
- fchown -> fchownat
- lchown -> fchownat
- mkfifo -> mkfifoat
- open -> openat
- renameat -> renameat2
- rmdir -> unlinkat
- unlink -> unlinkat
- symlink-> symlinkat

The `open_flags` logic for fstatat was redundant, as this is already
handled (and better so) in `openat2`.

Additionally, the fstatat test succeeds in os-test, and no longer
returns EINVAL. This is because `O_SYMLINK` is no longer
unconditionally passed like it was before. This is a problem because
redoxfs returns EINVAL if a node isn't a symlink but set `O_SYMLINK`.
This commit is contained in:
Connor-GH
2026-05-05 13:59:30 -05:00
parent 5312b86ee5
commit e2486379b1
4 changed files with 32 additions and 175 deletions
+3 -30
View File
@@ -5,10 +5,7 @@
use crate::{
c_str::CStr,
error::ResultExt,
header::{
fcntl::{AT_SYMLINK_NOFOLLOW, O_NOFOLLOW, O_PATH},
time::timespec,
},
header::{fcntl::AT_SYMLINK_NOFOLLOW, time::timespec},
out::Out,
platform::{
Pal, Sys,
@@ -147,19 +144,7 @@ pub unsafe extern "C" fn futimens(fd: c_int, times: *const timespec) -> c_int {
pub unsafe extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int {
let path = unsafe { CStr::from_ptr(path) };
let buf = unsafe { Out::nonnull(buf) };
// TODO: Rustify
let fd = Sys::open(path, O_PATH | O_NOFOLLOW, 0).or_minus_one_errno();
if fd < 0 {
return -1;
}
// TODO: Rustify
let res = Sys::fstat(fd, buf).map(|()| 0).or_minus_one_errno();
if let Ok(()) = Sys::close(fd) {}; // TODO handle error
res
Sys::lstat(path, buf).map(|()| 0).or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkdirat.html>.
@@ -220,19 +205,7 @@ pub unsafe extern "C" fn mknodat(
pub unsafe extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int {
let file = unsafe { CStr::from_ptr(file) };
let buf = unsafe { Out::nonnull(buf) };
// TODO: Rustify
let fd = Sys::open(file, O_PATH, 0).or_minus_one_errno();
if fd < 0 {
return -1;
}
// TODO: Rustify
let res = Sys::fstat(fd, buf).map(|()| 0).or_minus_one_errno();
if let Ok(()) = Sys::close(fd) {}; // TODO handle error
res
Sys::stat(file, buf).map(|()| 0).or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/umask.html>.