Skip to content

Commit 760ca08

Browse files
committed
Convert common syscalls to safe I/O types
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
1 parent e756c96 commit 760ca08

23 files changed

+754
-643
lines changed

src/dir.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::sys;
66
use crate::{Error, NixPath, Result};
77
use cfg_if::cfg_if;
88
use std::ffi;
9+
use std::os::unix::io::AsFd;
910
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
1011
use std::ptr;
1112

@@ -39,18 +40,18 @@ impl Dir {
3940
mode: sys::stat::Mode,
4041
) -> Result<Self> {
4142
let fd = fcntl::open(path, oflag, mode)?;
42-
Dir::from_fd(fd)
43+
Dir::from_fd(fd.into_raw_fd())
4344
}
4445

4546
/// Opens the given path as with `fcntl::openat`.
46-
pub fn openat<P: ?Sized + NixPath>(
47-
dirfd: RawFd,
47+
pub fn openat<Fd: AsFd, P: ?Sized + NixPath>(
48+
dirfd: &Fd,
4849
path: &P,
4950
oflag: OFlag,
5051
mode: sys::stat::Mode,
5152
) -> Result<Self> {
5253
let fd = fcntl::openat(dirfd, path, oflag, mode)?;
53-
Dir::from_fd(fd)
54+
Dir::from_fd(fd.into_raw_fd())
5455
}
5556

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

0 commit comments

Comments
 (0)