From eaaa82bd9c1e24a83dcea3857f5fd75d0dfb6de5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 20 Mar 2015 13:21:18 +0200 Subject: New consolidated load/match/build loop --- build/filesystem.cxx | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'build/filesystem.cxx') 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 -#include // rmdir(), unlink() -#include // mkdir() +#include // rmdir(), unlink() +#include // stat +#include // stat, lstat(), S_IS*, mkdir() #include @@ -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) { -- cgit v1.1