Skip to content

Commit

Permalink
Convert common syscalls to safe I/O types
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Dec 4, 2022
1 parent e756c96 commit 88b6ba9
Show file tree
Hide file tree
Showing 23 changed files with 745 additions and 643 deletions.
9 changes: 5 additions & 4 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::sys;
use crate::{Error, NixPath, Result};
use cfg_if::cfg_if;
use std::ffi;
use std::os::unix::io::AsFd;
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::ptr;

Expand Down Expand Up @@ -39,18 +40,18 @@ impl Dir {
mode: sys::stat::Mode,
) -> Result<Self> {
let fd = fcntl::open(path, oflag, mode)?;
Dir::from_fd(fd)
Dir::from_fd(fd.into_raw_fd())
}

/// Opens the given path as with `fcntl::openat`.
pub fn openat<P: ?Sized + NixPath>(
dirfd: RawFd,
pub fn openat<Fd: AsFd, P: ?Sized + NixPath>(
dirfd: &Fd,
path: &P,
oflag: OFlag,
mode: sys::stat::Mode,
) -> Result<Self> {
let fd = fcntl::openat(dirfd, path, oflag, mode)?;
Dir::from_fd(fd)
Dir::from_fd(fd.into_raw_fd())
}

/// Converts from a descriptor-based object, closing the descriptor on success or failure.
Expand Down
Loading

0 comments on commit 88b6ba9

Please sign in to comment.