aboutsummaryrefslogtreecommitdiff
path: root/build/filesystem.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-03-20 13:21:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-03-20 13:21:18 +0200
commiteaaa82bd9c1e24a83dcea3857f5fd75d0dfb6de5 (patch)
tree9d849682e5c8fb971382843064ea0c286d753cba /build/filesystem.cxx
parentb6e72877a1a26a6ae16961728ee57e45f657f717 (diff)
New consolidated load/match/build loop
Diffstat (limited to 'build/filesystem.cxx')
-rw-r--r--build/filesystem.cxx35
1 files changed, 33 insertions, 2 deletions
diff --git a/build/filesystem.cxx b/build/filesystem.cxx
index 75d0283..ee17fba 100644
--- a/build/filesystem.cxx
+++ b/build/filesystem.cxx
@@ -4,8 +4,9 @@
#include <build/filesystem>
-#include <unistd.h> // rmdir(), unlink()
-#include <sys/stat.h> // mkdir()
+#include <unistd.h> // rmdir(), unlink()
+#include <sys/types.h> // stat
+#include <sys/stat.h> // stat, lstat(), S_IS*, mkdir()
#include <system_error>
@@ -13,6 +14,36 @@ using namespace std;
namespace build
{
+ bool
+ dir_exists (const path& p)
+ {
+ struct stat s;
+ if (::lstat (p.string ().c_str (), &s) != 0)
+ {
+ if (errno == ENOENT || errno == ENOTDIR)
+ return false;
+ else
+ throw system_error (errno, system_category ());
+ }
+
+ return S_ISDIR (s.st_mode);
+ }
+
+ bool
+ file_exists (const path& p)
+ {
+ struct stat s;
+ if (::lstat (p.string ().c_str (), &s) != 0)
+ {
+ if (errno == ENOENT || errno == ENOTDIR)
+ return false;
+ else
+ throw system_error (errno, system_category ());
+ }
+
+ return S_ISREG (s.st_mode);
+ }
+
void
mkdir (const path& p, mode_t m)
{