Like the other "at" functions, renameat renames files with respect with
a directory descriptor. "renameat2" is Linux specific but really nice -
it adds a flag which supports atomically swapping two files or failing
if the target already exists. The latter is easily supported in relibc.
The former requires redoxfs support.
Besides the impl itself, I refactored "cap_path_at" into what it really
is: a mini openat2-like function.
Capability based `fchmod`. I also implemented unit tests for chmod,
fchmod, and fchmodat.
The unit tests check Redox-specific behavior, so some of the tests are
disabled for Linux.
`fdopendir` takes ownership of a directory file descriptor instead of
opening one with a path. `fdclosedir` is a FreeBSD extension that
transfers ownership of the file descriptor in DIR to the user.
Linux's variant uses the syscall as intended. Redox's variant uses fpath
to build a path to pass to fstat from the file descriptor plus the file
name. Unlike the syscall, this isn't atomic so the liminal space between
fpath/getcwd and fstat is subject to TOCTOU.
Beyond fstatat, I moved the stat test to its correct location and added
an assert since the output of the test is unchecked.
I also added AT_FDCWD which seems to be -100 across Unixes. The other
AT_* constants are unimplemented for now.
The implementation for confstr is straightforward. Most of the constants
return 1 on both musl and glibc. The only constant that doesn't is
required for Fish.
I also switched an #[unsafe(no_mangle)] from my last patch back
to a #[no_mangle] because we need to bump cbindgen. #[unsafe(no_mangle)]
is required for Rust 2024.
%m is a format specifier that prints an error string for errno. The
specifier is technically only for syslog, but musl and glibc implement
it for printf itself. Parsing for a single specifier in a single
function is error prone, especially when syslog itself is variadic.
* Fix PERROR to match musl/glibc better
* More unit tests + enabled on Linux
* Pack priority and facility into one i32 and check the bits with
bitflags
* Add LOG_UPTO (logic is straight from musl)
Not done:
* "%m" - this could just be added to printf
* LOG_CONS