1 /* 2 * Copyright (c) 2006-2022, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 */ 9 10 #ifndef __DIRENT_H__ 11 #define __DIRENT_H__ 12 13 #include <rtdef.h> 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /* 20 * dirent.h - format of directory entries 21 * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html 22 */ 23 24 /* File types */ 25 #define FT_REGULAR 0 /* regular file */ 26 #define FT_SOCKET 1 /* socket file */ 27 #define FT_DIRECTORY 2 /* directory */ 28 #define FT_USER 3 /* user defined */ 29 #define FT_DEVICE 4 /* device */ 30 #define FT_SYMLINK 5 /* symbol link */ 31 #define FT_NONLOCK 6 /* non lock */ 32 33 #define DT_UNKNOWN 0x00 34 #define DT_FIFO 0x01 35 #define DT_CHR 0x02 36 #define DT_DIR 0x04 37 #define DT_BLK 0x06 38 #define DT_REG 0x08 39 #define DT_LNK 0x0a 40 #define DT_SOCK 0x0c 41 #define DT_SYMLINK DT_LNK 42 43 #ifndef HAVE_DIR_STRUCTURE 44 #define HAVE_DIR_STRUCTURE 45 typedef struct 46 { 47 int fd; /* directory file */ 48 char buf[512]; 49 int num; 50 int cur; 51 }DIR; 52 #endif 53 54 #ifndef HAVE_DIRENT_STRUCTURE 55 #define HAVE_DIRENT_STRUCTURE 56 57 #define DIRENT_NAME_MAX 256 58 59 struct dirent 60 { 61 rt_uint8_t d_type; /* The type of the file */ 62 rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ 63 rt_uint16_t d_reclen; /* length of this record */ 64 char d_name[DIRENT_NAME_MAX]; /* The null-terminated file name */ 65 }; 66 #endif 67 68 #ifdef RT_USING_MUSLLIBC 69 typedef uint64_t ino_t; 70 #endif 71 struct libc_dirent { 72 #ifdef RT_USING_MUSLLIBC 73 ino_t d_ino; 74 #endif 75 off_t d_off; 76 unsigned short d_reclen; 77 unsigned char d_type; 78 char d_name[DIRENT_NAME_MAX]; 79 }; 80 81 int closedir(DIR *); 82 DIR *opendir(const char *); 83 struct dirent *readdir(DIR *); 84 int readdir_r(DIR *, struct dirent *, struct dirent **); 85 void rewinddir(DIR *); 86 void seekdir(DIR *, long); 87 long telldir(DIR *); 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif 94