Skip to content

add musl and glibc wrappers for getdents{,64} #4522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions libc-test/semver/linux-gnu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ fgetpwent_r
fgetspent_r
futimes
getauxval
getdents64
getentropy
getgrent_r
getloadavg
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/linux-musl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ euidaccess
explicit_bzero
futimes
getauxval
getdents
getdents64
getloadavg
getutxent
getutxid
Expand Down
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 @@ -1344,6 +1344,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;
}

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
4 changes: 4 additions & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,10 @@ extern "C" {
pub fn utmpxname(file: *const c_char) -> c_int;
}

extern "C" {
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
Loading