Merge branch 'add-posix-dent' into 'master'

Define posix_dent for posix_getdents

See merge request redox-os/relibc!746
This commit is contained in:
Jeremy Soller
2025-10-12 08:23:36 -06:00
4 changed files with 19 additions and 2 deletions
+1
View File
@@ -5,6 +5,7 @@
typedef long blksize_t;
typedef long dev_t;
typedef unsigned long ino_t;
typedef unsigned short reclen_t;
typedef int gid_t;
typedef int uid_t;
typedef int mode_t;
+15
View File
@@ -155,6 +155,18 @@ pub struct dirent {
pub d_name: [c_char; 256],
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/dirent.h.html>.
/// must have the same struct layout as dirent
#[repr(C)]
#[derive(Clone)]
pub struct posix_dent {
pub d_ino: ino_t,
pub d_off: off_t, // not specified by posix
pub d_reclen: reclen_t,
pub d_type: c_uchar,
pub d_name: [c_char; 256],
}
#[cfg(target_os = "redox")]
const _: () = {
use core::mem::{offset_of, size_of};
@@ -357,3 +369,6 @@ pub extern "C" fn seekdir(dir: &mut DIR, off: c_long) {
pub extern "C" fn telldir(dir: &mut DIR) -> c_long {
dir.opaque_offset as c_long
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn cbindgen_stupid_struct_user_for_posix_dent(a: posix_dent) {}
+1
View File
@@ -65,6 +65,7 @@ pub type gid_t = c_int;
pub type uid_t = c_int;
pub type dev_t = c_long;
pub type ino_t = c_ulonglong;
pub type reclen_t = c_ushort;
pub type nlink_t = c_ulong;
pub type blksize_t = c_long;
pub type blkcnt_t = c_ulong;
+2 -2
View File
@@ -14,7 +14,7 @@ void read_and_print_directory(int fd) {
char buffer[BUFFER_SIZE];
long nread;
long bpos;
struct dirent *d;
struct posix_dent *d;
for (;;) {
nread = posix_getdents(fd, buffer, BUFFER_SIZE, 0);
@@ -26,7 +26,7 @@ void read_and_print_directory(int fd) {
}
for (bpos = 0; bpos < nread;) {
d = (struct dirent *) (buffer + bpos);
d = (struct posix_dent *) (buffer + bpos);
printf(" ino = %-10lu name = %s\n", (unsigned long)d->d_ino, d->d_name);
bpos += d->d_reclen;
}