nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.63k stars 661 forks source link

refactor: I/O safety for modules fcntl and dir #2434

Closed SteveLauC closed 3 months ago

SteveLauC commented 3 months ago

What does this PR do

This PR adds I/O safety to fcntl.rs and dir.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:

  1. Define AT_FDCWD: BorrowedFd<'static>

  2. Change the signature to xxat<Fd: AsFd>(dirfd: Fd, ...)

    because:

  3. rustix has been using this interface for a long time, which means it would work pretty well.

  4. 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: