aboutsummaryrefslogtreecommitdiff
path: root/io/ftwtest.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-05-30 01:37:13 +0000
committerUlrich Drepper <drepper@redhat.com>1997-05-30 01:37:13 +0000
commitd951286f645cc1d6f719c0c715620fc395c049d4 (patch)
treeff756b3d8cb561d733337cf27bca2e26358852ba /io/ftwtest.c
parent76b87c039ba8d20add4f52ba43f3471fd92e210b (diff)
downloadglibc-d951286f645cc1d6f719c0c715620fc395c049d4.zip
glibc-d951286f645cc1d6f719c0c715620fc395c049d4.tar.gz
glibc-d951286f645cc1d6f719c0c715620fc395c049d4.tar.bz2
* io/Makefile (test-srcs): Add ftwtest. (distribute): Add ftwtest-sh. (tests): Call ftwtest-sh for this goal. * io/ftwtest-sh: New file. Sets up test environment, calls test program and compares the result. * io/ftwtest.c: Test program for ftw. * misc/search.h: Add comments. Declare tdestroy. * misc/tsearch.c (tdestroy): New function.
Diffstat (limited to 'io/ftwtest.c')
-rw-r--r--io/ftwtest.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/io/ftwtest.c b/io/ftwtest.c
new file mode 100644
index 0000000..6daa7e9
--- /dev/null
+++ b/io/ftwtest.c
@@ -0,0 +1,71 @@
+#include <ftw.h>
+#include <getopt.h>
+#include <mcheck.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+
+int do_depth;
+int do_chdir;
+int do_phys;
+
+struct option options[] =
+{
+ { "depth", no_argument, &do_depth, 1 },
+ { "chdir", no_argument, &do_chdir, 1 },
+ { "phys", no_argument, &do_phys, 1 },
+ { NULL, 0, NULL, 0 }
+};
+
+const char *flag2name[] =
+{
+ [FTW_F] = "FTW_F",
+ [FTW_D] = "FTW_D",
+ [FTW_DNR] = "FTW_DNR",
+ [FTW_NS] = "FTW_NS",
+ [FTW_SL] = "FTW_SL",
+ [FTW_DP] = "FTW_DP",
+ [FTW_SLN] = "FTW_SLN"
+};
+
+
+int
+cb (const char *name, const struct stat *st, int flag, struct FTW *f)
+{
+ printf ("base = \"%.*s\", file = \"%s\", flag = %s",
+ f->base, name, name + f->base, flag2name[flag]);
+ if (do_chdir)
+ {
+ char *cwd = getcwd (NULL, 0);
+ printf (", cwd = %s", cwd);
+ free (cwd);
+ }
+ puts ("");
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ int opt;
+ int r;
+ int flag = 0;
+ mtrace ();
+
+ while ((opt = getopt_long_only (argc, argv, "", options, NULL)) != -1)
+ ;
+
+ if (do_chdir)
+ flag |= FTW_CHDIR;
+ if (do_depth)
+ flag |= FTW_DEPTH;
+ if (do_phys)
+ flag |= FTW_PHYS;
+
+ r = nftw (optind < argc ? argv[optind] : ".", cb, 3, flag);
+ if (r)
+ perror ("nftw");
+ return r;
+}