`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.
* 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
From man dlopen(3)
> According to the ISO C standard, casting between function
> pointers and 'void *', as done above, produces undefined results.
> POSIX.1-2001 and POSIX.1-2008 accepted this state of affairs and
> proposed the following workaround:
>
> *(void **) (&cosine) = dlsym(handle, "cos");
>
> This (clumsy) cast conforms with the ISO C standard and will
> avoid any compiler warnings.
>
> The 2013 Technical Corrigendum 1 to POSIX.1-2008 improved matters
> by requiring that conforming implementations support casting
> 'void *' to a function pointer. Nevertheless, some compilers
> (e.g., gcc with the '-pedantic' option) may complain about the
> cast used in this program.
Signed-off-by: Anhad Singh <andypython@protonmail.com>