This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c7963707a3e382f9c6d87b3882e39bb5880ebe9e Author: Marco Casaroli <[email protected]> AuthorDate: Tue Oct 27 19:21:09 2026 +0100 include/dirent.h: Add IFTODT() and DTTOIF(). IFTODT() gives the d_type of a file type in st_mode, and DTTOIF() the st_mode file type of a d_type. The BSDs and glibc have them in <dirent.h>, and programs that walk directory trees use them (attr's walk_tree.c did not compile without them). The NuttX file types already follow the same rule as glibc: each S_IFxxx is DT_xxx << 12. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/dirent.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/dirent.h b/include/dirent.h index 3b8b95254c8..506a6d174d4 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -57,6 +57,13 @@ #define DT_LNK 10 #define DT_SOCK 12 +/* Convert between the file type of st_mode (S_IFMT bits, <sys/stat.h>) and + * d_type: each S_IFxxx is DT_xxx << 12, as in glibc and the BSDs. + */ + +#define IFTODT(mode) (((mode) & 0170000) >> 12) +#define DTTOIF(dtype) ((dtype) << 12) + /* File type code for the d_type field in dirent structure. * Note that because of the simplified filesystem organization of the NuttX, * top-level, pseudo-file system, an inode can be BOTH a file and a directory
