Skip to content

Commit 423017b

Browse files
add musl and glibc wrappers for getdents{,64}
1 parent d2ece10 commit 423017b

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
@@ -1346,6 +1346,13 @@ extern "C" {
13461346
pub fn mempcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
13471347
}
13481348

1349+
extern "C" {
1350+
// There is no glibc wrapper for the getdents system call, and getdents64() is only available
1351+
// from 2.30 onwards.
1352+
/// `buffer` points to a buffer of [`crate::dirent64`] structs.
1353+
pub fn getdents64(fd: c_int, buffer: *mut c_void, nbytes: usize) -> isize;
1354+
}
1355+
13491356
cfg_if! {
13501357
if #[cfg(any(
13511358
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)]
@@ -971,6 +980,12 @@ extern "C" {
971980
pub fn utmpxname(file: *const c_char) -> c_int;
972981
}
973982

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

0 commit comments

Comments
 (0)