Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add musl and glibc wrappers for getdents{,64}
  • Loading branch information
cosmicexplorer committed Sep 29, 2025
commit 423017b865e6570c60cf529537963d45ff2d40f9
7 changes: 7 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,13 @@ extern "C" {
pub fn mempcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
}

extern "C" {
// There is no glibc wrapper for the getdents system call, and getdents64() is only available
// from 2.30 onwards.
/// `buffer` points to a buffer of [`crate::dirent64`] structs.
pub fn getdents64(fd: c_int, buffer: *mut c_void, nbytes: usize) -> isize;
}
Comment on lines +1349 to +1354
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you merge this with the extern "C" block above?

Also no doc comments please, for this crate we defer to the platform manpages.


cfg_if! {
if #[cfg(any(
target_arch = "x86",
Expand Down
5 changes: 5 additions & 0 deletions src/unix/linux_like/linux/musl/lfs64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ pub unsafe extern "C" fn readdir64_r(
crate::readdir_r(dirp, entry as *mut _, result as *mut _)
}

#[inline]
pub unsafe extern "C" fn getdents64(fd: c_int, buf: *mut crate::dirent64, len: usize) -> c_int {
crate::getdents(fd, buf as *mut _, len)
}

#[inline]
pub unsafe extern "C" fn sendfile64(
out_fd: c_int,
Expand Down
15 changes: 15 additions & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ cfg_if! {
}
}

#[repr(C)]
pub struct posix_dent {
pub d_ino: ino_t,
pub d_off: off_t,
pub d_reclen: c_ushort,
pub d_type: c_uchar,
pub d_name: *mut c_char,
}

impl siginfo_t {
pub unsafe fn si_addr(&self) -> *mut c_void {
#[repr(C)]
Expand Down Expand Up @@ -971,6 +980,12 @@ extern "C" {
pub fn utmpxname(file: *const c_char) -> c_int;
}

extern "C" {
pub fn posix_getdents(fd: c_int, buf: *mut c_void, len: usize, flags: c_int) -> isize;

pub fn getdents(fd: c_int, buf: *mut crate::dirent, len: usize) -> c_int;
}

// Alias <foo> to <foo>64 to mimic glibc's LFS64 support
mod lfs64;
pub use self::lfs64::*;
Expand Down