Skip to content

Commit c0cfd85

Browse files
committed
Convert common syscalls to safe I/O types
Signed-off-by: Alex Saveau <[email protected]>
1 parent fbebb21 commit c0cfd85

22 files changed

+957
-823
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`.
4647
pub fn openat<P: ?Sized + NixPath>(
47-
dirfd: RawFd,
48+
dirfd: &impl AsFd,
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.
@@ -240,7 +241,7 @@ impl Entry {
240241

241242
/// Returns the bare file name of this directory entry without any other leading path component.
242243
pub fn file_name(&self) -> &ffi::CStr {
243-
unsafe { ::std::ffi::CStr::from_ptr(self.0.d_name.as_ptr()) }
244+
unsafe { ffi::CStr::from_ptr(self.0.d_name.as_ptr()) }
244245
}
245246

246247
/// Returns the type of this directory entry, if known.

0 commit comments

Comments
 (0)