dirent.h 1.4 KB

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