aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/llvm/System/Path.h8
-rw-r--r--lib/System/Unix/Path.inc8
-rw-r--r--lib/System/Win32/Path.inc7
3 files changed, 22 insertions, 1 deletions
diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h
index 57e0917..8ae8a00 100644
--- a/include/llvm/System/Path.h
+++ b/include/llvm/System/Path.h
@@ -321,7 +321,7 @@ namespace sys {
/// shared library.
/// @brief Determine if the path reference a dynamic library.
bool isDynamicLibrary() const;
-
+
/// This function determines if the path name references an existing file
/// or directory in the file system.
/// @returns true if the pathname references an existing file or
@@ -330,6 +330,12 @@ namespace sys {
/// the file system.
bool exists() const;
+ /// This function determines if the path name refences an
+ /// existing directory.
+ /// @returns true if the pathname references an existing directory.
+ /// @brief Determins if the path is a directory in the file system.
+ bool isDirectory() const;
+
/// This function determines if the path name references a readable file
/// or directory in the file system. This function checks for
/// the existence and readability (by the current program) of the file
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index e4916ba..9e90dda 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -289,6 +289,14 @@ Path::exists() const {
}
bool
+Path::isDirectory() const {
+ struct stat buf;
+ if (0 != stat(path.c_str(), &buf))
+ return false;
+ return buf.st_mode & S_IFDIR ? true : false;
+}
+
+bool
Path::canRead() const {
return 0 == access(path.c_str(), F_OK | R_OK );
}
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc
index 994bc67..2484b8a 100644
--- a/lib/System/Win32/Path.inc
+++ b/lib/System/Win32/Path.inc
@@ -254,6 +254,13 @@ Path::exists() const {
}
bool
+Path::isDirectory() const {
+ DWORD attr = GetFileAttributes(path.c_str());
+ return (attr != INVALID_FILE_ATTRIBUTES) &&
+ (attr & FILE_ATTRIBUTE_DIRECTORY);
+}
+
+bool
Path::canRead() const {
// FIXME: take security attributes into account.
DWORD attr = GetFileAttributes(path.c_str());