2 #include "git-compat-util.h"
5 #include "dir-iterator.h"
9 * tool-test dir-iterator [--follow-symlinks] [--pedantic] directory_path
11 int cmd__dir_iterator(int argc, const char **argv)
13 struct strbuf path = STRBUF_INIT;
14 struct dir_iterator *diter;
15 unsigned int flags = 0;
18 for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
19 if (strcmp(*argv, "--follow-symlinks") == 0)
20 flags |= DIR_ITERATOR_FOLLOW_SYMLINKS;
21 else if (strcmp(*argv, "--pedantic") == 0)
22 flags |= DIR_ITERATOR_PEDANTIC;
24 die("invalid option '%s'", *argv);
27 if (!*argv || argc != 1)
28 die("dir-iterator needs exactly one non-option argument");
30 strbuf_add(&path, *argv, strlen(*argv));
31 diter = dir_iterator_begin(path.buf, flags);
34 printf("dir_iterator_begin failure: %d\n", errno);
38 while ((iter_status = dir_iterator_advance(diter)) == ITER_OK) {
39 if (S_ISDIR(diter->st.st_mode))
41 else if (S_ISREG(diter->st.st_mode))
43 else if (S_ISLNK(diter->st.st_mode))
48 printf("(%s) [%s] %s\n", diter->relative_path, diter->basename,
52 if (iter_status != ITER_DONE) {
53 printf("dir_iterator_advance failure\n");