For those xxat() interfaces, I didn't introduce a new trait to represent directory file descriptors, instead, I took the way how rustix implements it:
Define AT_FDCWD: BorrowedFd<'static>
Change the signature to xxat<Fd: AsFd>(dirfd: Fd, ...)
because:
rustix has been using this interface for a long time, which means it would work pretty well.
It is indeed unfortunate that we cannot catch some errors at compile time, but we will eventually get notified at runtime, e.g., when passing a fd that is not a directory to dirfd, or using AT_FDCWD with non-xxat() functions.
Checklist:
[x] I have read CONTRIBUTING.md
[x] I have written necessary tests and rustdoc comments
[x] A change log has been added if this PR modifies nix's API
What does this PR do
This PR adds I/O safety to
fcntl.rs
anddir.rs
.Ref: #1750
xxat() interfaces
For those
xxat()
interfaces, I didn't introduce a new trait to represent directory file descriptors, instead, I took the way how rustix implements it:Define
AT_FDCWD: BorrowedFd<'static>
Change the signature to
xxat<Fd: AsFd>(dirfd: Fd, ...)
because:
rustix has been using this interface for a long time, which means it would work pretty well.
It is indeed unfortunate that we cannot catch some errors at compile time, but we will eventually get notified at runtime, e.g., when passing a fd that is not a directory to
dirfd
, or usingAT_FDCWD
with non-xxat()
functions.Checklist:
CONTRIBUTING.md