From 9918693037dce8aa4bb6f08741b6812923486c18 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 19 Jun 2024 11:26:03 +0200 Subject: Merging upstream version 1.76.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/rustix/src/backend/libc/fs/dir.rs | 34 +++++++++++++++++++++++---- vendor/rustix/src/backend/libc/fs/syscalls.rs | 14 ++++------- 2 files changed, 35 insertions(+), 13 deletions(-) (limited to 'vendor/rustix/src/backend/libc/fs') diff --git a/vendor/rustix/src/backend/libc/fs/dir.rs b/vendor/rustix/src/backend/libc/fs/dir.rs index 0df1ea1b5..82a0a908f 100644 --- a/vendor/rustix/src/backend/libc/fs/dir.rs +++ b/vendor/rustix/src/backend/libc/fs/dir.rs @@ -2,7 +2,7 @@ use super::types::FileType; use crate::backend::c; use crate::backend::conv::owned_fd; -use crate::fd::{AsFd, BorrowedFd}; +use crate::fd::{AsFd, BorrowedFd, OwnedFd}; use crate::ffi::{CStr, CString}; use crate::fs::{fcntl_getfl, openat, Mode, OFlags}; #[cfg(not(target_os = "vita"))] @@ -48,8 +48,34 @@ pub struct Dir { } impl Dir { - /// Construct a `Dir` that reads entries from the given directory - /// file descriptor. + /// Take ownership of `fd` and construct a `Dir` that reads entries from + /// the given directory file descriptor. + #[inline] + pub fn new>(fd: Fd) -> io::Result { + Self::_new(fd.into()) + } + + #[inline] + fn _new(fd: OwnedFd) -> io::Result { + let raw = owned_fd(fd); + unsafe { + let libc_dir = c::fdopendir(raw); + + if let Some(libc_dir) = NonNull::new(libc_dir) { + Ok(Self { + libc_dir, + any_errors: false, + }) + } else { + let err = io::Errno::last_os_error(); + let _ = c::close(raw); + Err(err) + } + } + } + + /// Borrow `fd` and construct a `Dir` that reads entries from the given + /// directory file descriptor. #[inline] pub fn read_from(fd: Fd) -> io::Result { Self::_read_from(fd.as_fd()) @@ -393,5 +419,5 @@ fn dir_iterator_handles_io_errors() { } assert!(matches!(dir.next(), Some(Err(_)))); - assert!(matches!(dir.next(), None)); + assert!(dir.next().is_none()); } diff --git a/vendor/rustix/src/backend/libc/fs/syscalls.rs b/vendor/rustix/src/backend/libc/fs/syscalls.rs index 5e0b62f8e..fcf069a83 100644 --- a/vendor/rustix/src/backend/libc/fs/syscalls.rs +++ b/vendor/rustix/src/backend/libc/fs/syscalls.rs @@ -2,8 +2,7 @@ use crate::backend::c; #[cfg(any( - apple, - linux_kernel, + not(target_os = "redox"), feature = "alloc", all(linux_kernel, feature = "procfs") ))] @@ -275,10 +274,7 @@ pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result { } } -#[cfg(all( - any(feature = "alloc", all(linux_kernel, feature = "procfs")), - not(target_os = "redox") -))] +#[cfg(not(target_os = "redox"))] #[inline] pub(crate) fn readlinkat( dirfd: BorrowedFd<'_>, @@ -660,7 +656,7 @@ pub(crate) fn lstat(path: &CStr) -> io::Result { } } -#[cfg(not(any(target_os = "aix", target_os = "espidf", target_os = "redox")))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result { // See the comments in `fstat` about using `crate::fs::statx` here. #[cfg(all( @@ -1703,7 +1699,7 @@ pub(crate) fn ftruncate(fd: BorrowedFd<'_>, length: u64) -> io::Result<()> { } #[cfg(any(linux_kernel, target_os = "freebsd"))] -pub(crate) fn memfd_create(path: &CStr, flags: MemfdFlags) -> io::Result { +pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result { #[cfg(target_os = "freebsd")] weakcall! { fn memfd_create( @@ -1720,7 +1716,7 @@ pub(crate) fn memfd_create(path: &CStr, flags: MemfdFlags) -> io::Result c::c_int } - unsafe { ret_owned_fd(memfd_create(c_str(path), bitflags_bits!(flags))) } + unsafe { ret_owned_fd(memfd_create(c_str(name), bitflags_bits!(flags))) } } #[cfg(linux_kernel)] -- cgit v1.2.3