1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <stddef.h> 18 #include <stdint.h> 19 20 /** 21 * This header file provides POSIX-compatible definitions of directory 22 * access data types. Starting with newlib 3.3, related functions are defined 23 * in 'dirent.h' bundled with newlib. 24 * See http://pubs.opengroup.org/onlinepubs/7908799/xsh/dirent.h.html 25 * for reference. 26 */ 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /** 33 * @brief Opaque directory structure 34 */ 35 typedef struct { 36 uint16_t dd_vfs_idx; /*!< VFS index, not to be used by applications */ 37 uint16_t dd_rsv; /*!< field reserved for future extension */ 38 /* remaining fields are defined by VFS implementation */ 39 } DIR; 40 41 /** 42 * @brief Directory entry structure 43 */ 44 struct dirent { 45 int d_ino; /*!< file number */ 46 uint8_t d_type; /*!< not defined in POSIX, but present in BSD and Linux */ 47 #define DT_UNKNOWN 0 48 #define DT_REG 1 49 #define DT_DIR 2 50 #if __BSD_VISIBLE 51 #define MAXNAMLEN 255 52 char d_name[MAXNAMLEN+1]; /*!< zero-terminated file name */ 53 #else 54 char d_name[256]; 55 #endif 56 }; 57 58 DIR* opendir(const char* name); 59 struct dirent* readdir(DIR* pdir); 60 long telldir(DIR* pdir); 61 void seekdir(DIR* pdir, long loc); 62 void rewinddir(DIR* pdir); 63 int closedir(DIR* pdir); 64 int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent); 65 66 #ifdef __cplusplus 67 } 68 #endif 69