unicode: update the width tables to Unicode 15
[git.git] / t / helper / test-dir-iterator.c
blob6b297bd75361407fbba7cb6dcab0190d5ef5a1b2
1 #include "test-tool.h"
2 #include "git-compat-util.h"
3 #include "strbuf.h"
4 #include "iterator.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";
17 * usage:
18 * tool-test dir-iterator [--pedantic] directory_path
20 int cmd__dir_iterator(int argc, const char **argv)
22 struct dir_iterator *diter;
23 unsigned int flags = 0;
24 int iter_status;
26 for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
27 if (strcmp(*argv, "--pedantic") == 0)
28 flags |= DIR_ITERATOR_PEDANTIC;
29 else
30 die("invalid option '%s'", *argv);
33 if (!*argv || argc != 1)
34 die("dir-iterator needs exactly one non-option argument");
36 diter = dir_iterator_begin(*argv, flags);
38 if (!diter) {
39 printf("dir_iterator_begin failure: %s\n", error_name(errno));
40 exit(EXIT_FAILURE);
43 while ((iter_status = dir_iterator_advance(diter)) == ITER_OK) {
44 if (S_ISDIR(diter->st.st_mode))
45 printf("[d] ");
46 else if (S_ISREG(diter->st.st_mode))
47 printf("[f] ");
48 else if (S_ISLNK(diter->st.st_mode))
49 printf("[s] ");
50 else
51 printf("[?] ");
53 printf("(%s) [%s] %s\n", diter->relative_path, diter->basename,
54 diter->path.buf);
57 if (iter_status != ITER_DONE) {
58 printf("dir_iterator_advance failure\n");
59 return 1;
62 return 0;