Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/backend/libc/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ impl Dir {
}
}

/// Returns the file descriptor associated with the directory stream.
///
/// The file descriptor is used internally by the directory stream. As a result, it is useful
/// only for functions which do not depend or alter the file position.
///
/// # References
///
/// - [POSIX]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/dirfd.html
#[inline]
#[doc(alias = "dirfd")]
pub fn fd<'a>(&'a self) -> io::Result<BorrowedFd<'a>> {
let raw_fd = unsafe { c::dirfd(self.libc_dir.as_ptr()) };
if raw_fd < 0 {
Err(io::Errno::last_os_error())
} else {
Ok(unsafe { BorrowedFd::borrow_raw(raw_fd) })
}
}

/// Borrow `fd` and construct a `Dir` that reads entries from the given
/// directory file descriptor.
#[inline]
Expand Down
16 changes: 16 additions & 0 deletions src/backend/linux_raw/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ impl Dir {
})
}

/// Returns the file descriptor associated with the directory stream.
///
/// The file descriptor is used internally by the directory stream. As a result, it is useful
/// only for functions which do not depend or alter the file position.
///
/// # References
///
/// - [POSIX]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/dirfd.html
#[inline]
#[doc(alias = "dirfd")]
pub fn fd<'a>(&'a self) -> io::Result<BorrowedFd<'a>> {
Ok(self.fd.as_fd())
}

/// Borrow `fd` and construct a `Dir` that reads entries from the given
/// directory file descriptor.
#[inline]
Expand Down
Loading