fts.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #include <sys/types.h>
  3. #include <util/system/defaults.h>
  4. #ifndef _win32_
  5. typedef int dird;
  6. typedef struct stat stat_struct;
  7. #define STAT_FUNC stat
  8. #else
  9. #include <util/folder/dirent_win.h>
  10. typedef WCHAR* dird;
  11. typedef unsigned short u_short;
  12. typedef unsigned int nlink_t;
  13. typedef struct _stat64 stat_struct;
  14. #define STAT_FUNC stat64UTF
  15. //TODO: remove from global scope stat64UTF stat64UTF
  16. #ifdef __cplusplus
  17. int stat64UTF(const char* path, struct _stat64* _Stat);
  18. int stat64UTF(dird path, struct _stat64* _Stat);
  19. #endif
  20. #endif
  21. typedef struct {
  22. struct _ftsent* fts_cur; /* current node */
  23. struct _ftsent* fts_child; /* linked list of children */
  24. struct _ftsent** fts_array; /* sort array */
  25. dev_t fts_dev; /* starting device # */
  26. char* fts_path; /* path for this descent */
  27. dird fts_rfd; /* fd for root */
  28. int fts_pathlen; /* sizeof(path) */
  29. int fts_nitems; /* elements in the sort array */
  30. int(*fts_compar) /* compare function */
  31. (const struct _ftsent**, const struct _ftsent**);
  32. #define FTS_COMFOLLOW 0x001 /* follow command line symlinks */
  33. #define FTS_LOGICAL 0x002 /* logical walk */
  34. #define FTS_NOCHDIR 0x004 /* don't change directories */
  35. #define FTS_NOSTAT 0x008 /* don't get stat info */
  36. #define FTS_PHYSICAL 0x010 /* physical walk */
  37. #define FTS_SEEDOT 0x020 /* return dot and dot-dot */
  38. #define FTS_XDEV 0x040 /* don't cross devices */
  39. #define FTS_OPTIONMASK 0x0ff /* valid user option mask */
  40. #define FTS_NAMEONLY 0x100 /* (private) child names only */
  41. #define FTS_STOP 0x200 /* (private) unrecoverable error */
  42. int fts_options; /* yfts_open options, global flags */
  43. } FTS;
  44. typedef struct _ftsent {
  45. struct _ftsent* fts_cycle; /* cycle node */
  46. struct _ftsent* fts_parent; /* parent directory */
  47. struct _ftsent* fts_link; /* next file in directory */
  48. long fts_number; /* local numeric value */
  49. void* fts_pointer; /* local address value */
  50. char* fts_accpath; /* access path */
  51. char* fts_path; /* root path */
  52. int fts_errno; /* errno for this node */
  53. dird fts_symfd; /* fd for symlink */
  54. u_short fts_pathlen; /* strlen(fts_path) */
  55. u_short fts_namelen; /* strlen(fts_name) */
  56. ino_t fts_ino; /* inode */
  57. dev_t fts_dev; /* device */
  58. nlink_t fts_nlink; /* link count */
  59. #define FTS_ROOTPARENTLEVEL -1
  60. #define FTS_ROOTLEVEL 0
  61. short fts_level; /* depth (-1 to N) */
  62. #define FTS_D 1 /* preorder directory */
  63. #define FTS_DC 2 /* directory that causes cycles */
  64. #define FTS_DEFAULT 3 /* none of the above */
  65. #define FTS_DNR 4 /* unreadable directory */
  66. #define FTS_DOT 5 /* dot or dot-dot */
  67. #define FTS_DP 6 /* postorder directory */
  68. #define FTS_ERR 7 /* error; errno is set */
  69. #define FTS_F 8 /* regular file */
  70. #define FTS_INIT 9 /* initialized only */
  71. #define FTS_NS 10 /* stat(2) failed */
  72. #define FTS_NSOK 11 /* no stat(2) requested */
  73. #define FTS_SL 12 /* symbolic link */
  74. #define FTS_SLNONE 13 /* symbolic link without target */
  75. #define FTS_W 14 /* whiteout object */
  76. u_short fts_info; /* user flags for FTSENT structure */
  77. u_short fts_type; /* type of fs node; one of FTS_D, FTS_F, FTS_SL */
  78. #define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
  79. #define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
  80. #define FTS_ISW 0x04 /* this is a whiteout object */
  81. u_short fts_flags; /* private flags for FTSENT structure */
  82. #define FTS_AGAIN 1 /* read node again */
  83. #define FTS_FOLLOW 2 /* follow symbolic link */
  84. #define FTS_NOINSTR 3 /* no instructions */
  85. #define FTS_SKIP 4 /* discard node */
  86. u_short fts_instr; /* yfts_set() instructions */
  87. stat_struct* fts_statp; /* stat(2) information */
  88. char fts_name[1]; /* file name */
  89. } FTSENT;
  90. FTSENT* yfts_children(FTS*, int);
  91. int yfts_close(FTS*);
  92. FTS* yfts_open(char* const*, int, int (*)(const FTSENT**, const FTSENT**));
  93. FTSENT* yfts_read(FTS*);
  94. int yfts_set(FTS*, FTSENT*, int);