diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/rustix/src/backend/libc/fs | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/backend/libc/fs')
-rw-r--r-- | vendor/rustix/src/backend/libc/fs/dir.rs | 34 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/fs/syscalls.rs | 14 |
2 files changed, 35 insertions, 13 deletions
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: Into<OwnedFd>>(fd: Fd) -> io::Result<Self> { + Self::_new(fd.into()) + } + + #[inline] + fn _new(fd: OwnedFd) -> io::Result<Self> { + 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: AsFd>(fd: Fd) -> io::Result<Self> { 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<usize> { } } -#[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<Stat> { } } -#[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<Stat> { // 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<OwnedFd> { +pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd> { #[cfg(target_os = "freebsd")] weakcall! { fn memfd_create( @@ -1720,7 +1716,7 @@ pub(crate) fn memfd_create(path: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd ) via SYS_memfd_create -> 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)] |