Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rust
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ea9181ba77c042bd8c7a5daee497f15c67917488
Choose a base ref
..
head repository: rust-lang/rust
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4839b81c0637ed00e119fc63ea1c275b76e7917a
Choose a head ref
Showing with 6 additions and 9 deletions.
  1. +6 −9 library/std/src/sys/unix/fs.rs
15 changes: 6 additions & 9 deletions library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ use libc::fstatat64;
use libc::readdir as readdir64;
#[cfg(target_os = "linux")]
use libc::readdir64;
#[cfg(any(target_os = "emscripten", target_os = "l4re"))]
use libc::readdir64_r;
#[cfg(not(any(
target_os = "linux",
target_os = "emscripten",
@@ -237,7 +239,7 @@ pub struct DirEntry {
target_os = "fuchsia",
target_os = "redox"
))]
name: Box<[u8]>,
name: Box<CStr>,
}

#[derive(Clone, Debug)]
@@ -465,8 +467,6 @@ impl Iterator for ReadDir {
target_os = "illumos"
))]
fn next(&mut self) -> Option<io::Result<DirEntry>> {
use crate::slice;

unsafe {
loop {
// Although readdir_r(3) would be a correct function to use here because
@@ -485,14 +485,11 @@ impl Iterator for ReadDir {
}

let name = (*entry_ptr).d_name.as_ptr();
let namelen = libc::strlen(name) as usize;

let ret = DirEntry {
entry: *entry_ptr,
name: slice::from_raw_parts(name as *const u8, namelen as usize)
.to_owned()
.into_boxed_slice(),
dir: Arc::clone(&self.inner),
name: CStr::from_ptr(name).into(),
};
if ret.name_bytes() != b"." && ret.name_bytes() != b".." {
return Some(Ok(ret));
@@ -558,7 +555,7 @@ impl DirEntry {
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
pub fn metadata(&self) -> io::Result<FileAttr> {
let fd = cvt(unsafe { dirfd(self.dir.dirp.0) })?;
let name = self.entry.d_name.as_ptr();
let name = self.name.as_ptr();

cfg_has_statx! {
if let Some(ret) = unsafe { try_statx(
@@ -675,7 +672,7 @@ impl DirEntry {
target_os = "redox"
))]
fn name_bytes(&self) -> &[u8] {
&*self.name
self.name.to_bytes()
}

pub fn file_name_os_str(&self) -> &OsStr {