aboutsummaryrefslogtreecommitdiff
path: root/build/filesystem.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-03-12 15:43:17 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-03-12 15:43:17 +0200
commitcf6b3e34b59ad120111e0c1ead779bbb3a70c38d (patch)
tree424e9def98c65d9080e72a69064334c6716fb82b /build/filesystem.cxx
parent5925c11a1fe8b2e02b790dd40b031ae005d5b68f (diff)
Implement clean operation
Diffstat (limited to 'build/filesystem.cxx')
-rw-r--r--build/filesystem.cxx56
1 files changed, 56 insertions, 0 deletions
diff --git a/build/filesystem.cxx b/build/filesystem.cxx
new file mode 100644
index 0000000..75d0283
--- /dev/null
+++ b/build/filesystem.cxx
@@ -0,0 +1,56 @@
+// file : build/filesystem.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <build/filesystem>
+
+#include <unistd.h> // rmdir(), unlink()
+#include <sys/stat.h> // mkdir()
+
+#include <system_error>
+
+using namespace std;
+
+namespace build
+{
+ void
+ mkdir (const path& p, mode_t m)
+ {
+ if (::mkdir (p.string ().c_str (), m) != 0)
+ throw system_error (errno, system_category ());
+ }
+
+ rmdir_status
+ try_rmdir (const path& p)
+ {
+ rmdir_status r (rmdir_status::success);
+
+ if (::rmdir (p.string ().c_str ()) != 0)
+ {
+ if (errno == ENOENT)
+ r = rmdir_status::not_exist;
+ else if (errno == ENOTEMPTY || errno == EEXIST)
+ r = rmdir_status::not_empty;
+ else
+ throw system_error (errno, system_category ());
+ }
+
+ return r;
+ }
+
+ rmfile_status
+ try_rmfile (const path& p)
+ {
+ rmfile_status r (rmfile_status::success);
+
+ if (::unlink (p.string ().c_str ()) != 0)
+ {
+ if (errno == ENOENT || errno == ENOTDIR)
+ r = rmfile_status::not_exist;
+ else
+ throw system_error (errno, system_category ());
+ }
+
+ return r;
+ }
+}