16 struct option options
[] =
18 { "depth", no_argument
, &do_depth
, 1 },
19 { "chdir", no_argument
, &do_chdir
, 1 },
20 { "phys", no_argument
, &do_phys
, 1 },
21 { "early-exit", no_argument
, &do_exit
, 1 },
25 const char *flag2name
[] =
29 [FTW_DNR
] = "FTW_DNR",
38 cb (const char *name
, const struct stat
*st
, int flag
, struct FTW
*f
)
40 if (do_exit
&& strcmp (name
+ f
->base
, "file@2"))
43 printf ("base = \"%.*s\", file = \"%s\", flag = %s",
44 f
->base
, name
, name
+ f
->base
, flag2name
[flag
]);
47 char *cwd
= getcwd (NULL
, 0);
48 printf (", cwd = %s", cwd
);
51 printf (", level = %d\n", f
->level
);
52 return do_exit
? 26 : 0;
56 main (int argc
, char *argv
[])
63 while ((opt
= getopt_long_only (argc
, argv
, "", options
, NULL
)) != -1)
73 r
= nftw (optind
< argc
? argv
[optind
] : ".", cb
, do_exit
? 1 : 3, flag
);
78 puts (r
== 26 ? "succeeded" : "failed");
79 return r
== 26 ? 0 : 1;