From fd52711675cb581e7672f131046e355a2b5ba167 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 18 Dec 2007 19:46:22 +0000 Subject: Added "isDirectory" method to llvm::sys::Path. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45168 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/System/Unix/Path.inc | 8 ++++++++ lib/System/Win32/Path.inc | 7 +++++++ 2 files changed, 15 insertions(+) (limited to 'lib/System') 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()); -- cgit v1.1