dirent.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #pragma once
  15. #include <stddef.h>
  16. #include <stdint.h>
  17. /**
  18. * This header file provides POSIX-compatible definitions of directory
  19. * access data types. Starting with newlib 3.3, related functions are defined
  20. * in 'dirent.h' bundled with newlib.
  21. * See http://pubs.opengroup.org/onlinepubs/7908799/xsh/dirent.h.html
  22. * for reference.
  23. */
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /**
  28. * @brief Opaque directory structure
  29. */
  30. typedef struct {
  31. uint16_t dd_vfs_idx; /*!< VFS index, not to be used by applications */
  32. uint16_t dd_rsv; /*!< field reserved for future extension */
  33. /* remaining fields are defined by VFS implementation */
  34. } DIR;
  35. /**
  36. * @brief Directory entry structure
  37. */
  38. struct dirent {
  39. int d_ino; /*!< file number */
  40. uint8_t d_type; /*!< not defined in POSIX, but present in BSD and Linux */
  41. #define DT_UNKNOWN 0
  42. #define DT_REG 1
  43. #define DT_DIR 2
  44. #if __BSD_VISIBLE
  45. #define MAXNAMLEN 255
  46. char d_name[MAXNAMLEN+1]; /*!< zero-terminated file name */
  47. #else
  48. char d_name[256];
  49. #endif
  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. #ifdef __cplusplus
  59. }
  60. #endif