7 * Iterate over a directory tree.
9 * Iterate over a directory tree, recursively, including paths of all
10 * types and hidden paths. Skip "." and ".." entries and don't follow
11 * symlinks except for the original path.
13 * Every time dir_iterator_advance() is called, update the members of
14 * the dir_iterator structure to reflect the next path in the
15 * iteration. The order that paths are iterated over within a
16 * directory is undefined, but directory paths are always iterated
17 * over before the subdirectory contents.
19 * A typical iteration looks like this:
22 * struct iterator *iter = dir_iterator_begin(path);
24 * while ((ok = dir_iterator_advance(iter)) == ITER_OK) {
25 * if (want_to_stop_iteration()) {
26 * ok = dir_iterator_abort(iter);
30 * // Access information about the current path:
31 * if (S_ISDIR(iter->st.st_mode))
32 * printf("%s is a directory\n", iter->relative_path);
35 * if (ok != ITER_DONE)
38 * Callers are allowed to modify iter->path while they are working,
39 * but they must restore it to its original contents before calling
40 * dir_iterator_advance() again.
44 /* The current path: */
48 * The current path relative to the starting path. This part
49 * of the path always uses "/" characters to separate path
52 const char *relative_path
;
54 /* The current basename: */
57 /* The result of calling lstat() on path: */
62 * Start a directory iteration over path. Return a dir_iterator that
63 * holds the internal state of the iteration.
65 * The iteration includes all paths under path, not including path
66 * itself and not including "." or ".." entries.
68 * path is the starting directory. An internal copy will be made.
70 struct dir_iterator
*dir_iterator_begin(const char *path
);
73 * Advance the iterator to the first or next item and return ITER_OK.
74 * If the iteration is exhausted, free the dir_iterator and any
75 * resources associated with it and return ITER_DONE. On error, free
76 * dir_iterator and associated resources and return ITER_ERROR. It is
77 * a bug to use iterator or call this function again after it has
78 * returned ITER_DONE or ITER_ERROR.
80 int dir_iterator_advance(struct dir_iterator
*iterator
);
83 * End the iteration before it has been exhausted. Free the
84 * dir_iterator and any associated resources and return ITER_DONE. On
85 * error, free the dir_iterator and return ITER_ERROR.
87 int dir_iterator_abort(struct dir_iterator
*iterator
);