aboutsummaryrefslogtreecommitdiff
path: root/tests/dir-iterator/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dir-iterator/driver.cxx')
-rw-r--r--tests/dir-iterator/driver.cxx55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/dir-iterator/driver.cxx b/tests/dir-iterator/driver.cxx
new file mode 100644
index 0000000..09a259f
--- /dev/null
+++ b/tests/dir-iterator/driver.cxx
@@ -0,0 +1,55 @@
+// file : tests/dir-iterator/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <cstddef> // size_t
+#include <cassert>
+#include <iostream>
+
+#include <butl/path>
+#include <butl/path-io>
+#include <butl/filesystem>
+
+using namespace std;
+using namespace butl;
+
+static const char* entry_type_string[] =
+{
+ "unk", "reg", "dir", "sym", "oth"
+};
+
+inline ostream&
+operator<< (ostream& os, entry_type e)
+{
+ return os << entry_type_string[static_cast<size_t> (e)];
+}
+
+int
+main (int argc, const char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " <dir>" << endl;
+ return 1;
+ }
+
+ try
+ {
+ for (const dir_entry& de: dir_iterator (dir_path (argv[1])))
+ {
+ cerr << de.type () << " ";
+
+ if (de.type () == entry_type::symlink)
+ cerr << de.ltype ();
+ else
+ cerr << " ";
+
+ cerr << " " << de.path () << endl;
+ }
+ }
+ catch (const exception& e)
+ {
+ cerr << argv[1] << ": " << e.what () << endl;
+ return 1;
+ }
+}