Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the interface of openat(dirfd: RawFd, ...) to openat(dirfd: Option<RawFd>, ...) #1850

Closed
SteveLauC opened this issue Oct 22, 2022 · 3 comments

Comments

@SteveLauC
Copy link
Member

Almost every xxxat() function takes an optional dirfd, except fcntl::openat(2) and Dir::openat()

pub fn openat<P: ?Sized + NixPath>(
    dirfd: RawFd,
    path: &P,
    oflag: OFlag,
    mode: Mode,
) -> Result<RawFd> 
pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: sys::stat::Mode) -> Result<Self> {
    let fd = fcntl::openat(dirfd, path, oflag, mode)?;
    Dir::from_fd(fd)
}

Any reason why it does not take an Option<RawFd>?

@SUPERCILEX
Copy link
Contributor

We should just do something similar to https://docs.rs/rustix/latest/src/rustix/fs/cwd.rs.html#26-32 (but as a const) while implementing #1750.

@asomers
Copy link
Member

asomers commented Nov 19, 2022

Git archaeology doesn't show any good reason why the functions take a RawFd. I agree that an Option would be better.

@SteveLauC
Copy link
Member Author

Close as completed in #2139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants