Skip to content

Commit a23fedf

Browse files
add musl and glibc wrappers for getdents{,64}
1 parent 3f8a0e3 commit a23fedf

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,13 @@ extern "C" {
13441344
pub fn mempcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
13451345
}
13461346

1347+
extern "C" {
1348+
// There is no glibc wrapper for the getdents system call, and getdents64() is only available
1349+
// from 2.30 onwards.
1350+
/// `buffer` points to a buffer of [`crate::dirent64`] structs.
1351+
pub fn getdents64(fd: c_int, buffer: *mut c_void, nbytes: usize) -> isize;
1352+
}
1353+
13471354
cfg_if! {
13481355
if #[cfg(any(
13491356
target_arch = "x86",

src/unix/linux_like/linux/musl/lfs64.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ pub unsafe extern "C" fn readdir64_r(
198198
crate::readdir_r(dirp, entry as *mut _, result as *mut _)
199199
}
200200

201+
#[inline]
202+
pub unsafe extern "C" fn getdents64(fd: c_int, buf: *mut crate::dirent64, len: usize) -> c_int {
203+
crate::getdents(fd, buf as *mut _, len)
204+
}
205+
201206
#[inline]
202207
pub unsafe extern "C" fn sendfile64(
203208
out_fd: c_int,

src/unix/linux_like/linux/musl/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ cfg_if! {
3737
}
3838
}
3939

40+
#[repr(C)]
41+
pub struct posix_dent {
42+
pub d_ino: ino_t,
43+
pub d_off: off_t,
44+
pub d_reclen: c_ushort,
45+
pub d_type: c_uchar,
46+
pub d_name: *mut c_char,
47+
}
48+
4049
impl siginfo_t {
4150
pub unsafe fn si_addr(&self) -> *mut c_void {
4251
#[repr(C)]
@@ -974,6 +983,12 @@ extern "C" {
974983
pub fn utmpxname(file: *const c_char) -> c_int;
975984
}
976985

986+
extern "C" {
987+
pub fn posix_getdents(fd: c_int, buf: *mut c_void, len: usize, flags: c_int) -> isize;
988+
989+
pub fn getdents(fd: c_int, buf: *mut crate::dirent, len: usize) -> c_int;
990+
}
991+
977992
// Alias <foo> to <foo>64 to mimic glibc's LFS64 support
978993
mod lfs64;
979994
pub use self::lfs64::*;

0 commit comments

Comments
 (0)