2 #include "git-compat-util.h"
5 #include "dir-iterator.h"
7 static const char *error_name(int error_number
)
9 switch (error_number
) {
10 case ENOENT
: return "ENOENT";
11 case ENOTDIR
: return "ENOTDIR";
12 default: return "ESOMETHINGELSE";
18 * tool-test dir-iterator [--follow-symlinks] [--pedantic] directory_path
20 int cmd__dir_iterator(int argc
, const char **argv
)
22 struct dir_iterator
*diter
;
23 unsigned int flags
= 0;
26 for (++argv
, --argc
; *argv
&& starts_with(*argv
, "--"); ++argv
, --argc
) {
27 if (strcmp(*argv
, "--follow-symlinks") == 0)
28 flags
|= DIR_ITERATOR_FOLLOW_SYMLINKS
;
29 else if (strcmp(*argv
, "--pedantic") == 0)
30 flags
|= DIR_ITERATOR_PEDANTIC
;
32 die("invalid option '%s'", *argv
);
35 if (!*argv
|| argc
!= 1)
36 die("dir-iterator needs exactly one non-option argument");
38 diter
= dir_iterator_begin(*argv
, flags
);
41 printf("dir_iterator_begin failure: %s\n", error_name(errno
));
45 while ((iter_status
= dir_iterator_advance(diter
)) == ITER_OK
) {
46 if (S_ISDIR(diter
->st
.st_mode
))
48 else if (S_ISREG(diter
->st
.st_mode
))
50 else if (S_ISLNK(diter
->st
.st_mode
))
55 printf("(%s) [%s] %s\n", diter
->relative_path
, diter
->basename
,
59 if (iter_status
!= ITER_DONE
) {
60 printf("dir_iterator_advance failure\n");