From 16e85bab8b32af7ceedc42ff5301c4a4a20b0a42 Mon Sep 17 00:00:00 2001 From: auronandace Date: Mon, 27 Apr 2026 08:06:45 +0100 Subject: [PATCH] move some constants from cbindgen to Rust in dirent --- src/header/dirent/cbindgen.toml | 13 +++---------- src/header/dirent/mod.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/header/dirent/cbindgen.toml b/src/header/dirent/cbindgen.toml index 6445e03377..e229472647 100644 --- a/src/header/dirent/cbindgen.toml +++ b/src/header/dirent/cbindgen.toml @@ -6,17 +6,10 @@ sys_includes = ["sys/types.h"] include_guard = "_RELIBC_DIRENT_H" language = "C" style = "Both" -trailer = """ +after_includes = """ + // Shamelessly stolen from musl -#define DT_UNKNOWN 0 -#define DT_FIFO 1 -#define DT_CHR 2 -#define DT_DIR 4 -#define DT_BLK 6 -#define DT_REG 8 -#define DT_LNK 10 -#define DT_SOCK 12 -#define DT_WHT 14 +// Macros to convert between struct dirent and struct stat types. #define IFTODT(x) ((x)>>12 & 017) #define DTTOIF(x) ((x)<<12) """ diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs index e0c53fbc57..17eccf0b4e 100644 --- a/src/header/dirent/mod.rs +++ b/src/header/dirent/mod.rs @@ -24,6 +24,31 @@ use crate::{ }, }; +// values of below constants taken from musl + +/// Unknown file type. +pub const DT_UNKNOWN: c_int = 0; +/// FIFO special. +pub const DT_FIFO: c_int = 1; +/// Character special. +pub const DT_CHR: c_int = 2; +/// Directory. +pub const DT_DIR: c_int = 4; +/// Block special. +pub const DT_BLK: c_int = 6; +/// Regular. +pub const DT_REG: c_int = 8; +/// Symbolic link. +pub const DT_LNK: c_int = 10; +/// Socket. +pub const DT_SOCK: c_int = 12; +/// Non-POSIX. +/// Whiteout inode. +pub const DT_WHT: c_int = 14; + +// values of above constants taken from musl + +/// cbindgen:ignore const INITIAL_BUFSIZE: usize = 512; /// See . @@ -163,6 +188,7 @@ pub struct posix_dent { pub d_name: [c_char; 256], } +/// cbindgen:ignore #[cfg(target_os = "redox")] const _: () = { use core::mem::{offset_of, size_of};