1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stddef.h>
10 #include <stdint.h>
11 #include <sys/types.h>
12 
13 /**
14  * This header file provides POSIX-compatible definitions of directory
15  * access data types. Starting with newlib 3.3, related functions are defined
16  * in 'dirent.h' bundled with newlib.
17  * See http://pubs.opengroup.org/onlinepubs/7908799/xsh/dirent.h.html
18  * for reference.
19  */
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * @brief Opaque directory structure
27  */
28 typedef struct {
29     uint16_t dd_vfs_idx; /*!< VFS index, not to be used by applications */
30     uint16_t dd_rsv;     /*!< field reserved for future extension */
31     /* remaining fields are defined by VFS implementation */
32 } DIR;
33 
34 /**
35  * @brief Directory entry structure
36  */
37 struct dirent {
38     ino_t d_ino;          /*!< file number */
39     uint8_t d_type;     /*!< not defined in POSIX, but present in BSD and Linux */
40 #define DT_UNKNOWN  0
41 #define DT_REG      1
42 #define DT_DIR      2
43 #if __BSD_VISIBLE
44 #define MAXNAMLEN 255
45     char d_name[MAXNAMLEN+1];   /*!< zero-terminated file name */
46 #else
47     char d_name[256];
48 #endif
49 };
50 
51 DIR* opendir(const char* name);
52 struct dirent* readdir(DIR* pdir);
53 long telldir(DIR* pdir);
54 void seekdir(DIR* pdir, long loc);
55 void rewinddir(DIR* pdir);
56 int closedir(DIR* pdir);
57 int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent);
58 
59 #ifdef __cplusplus
60 }
61 #endif
62