summaryrefslogtreecommitdiffstats
path: root/src/gtest-filepath.cc
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-03-26 19:03:47 (GMT)
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-03-26 19:03:47 (GMT)
commit3c7bbf5b46679aea4e0ac7d3ad241cb036146751 (patch)
treef452879c8f86232be2dec970ec7bce3a9963ed49 /src/gtest-filepath.cc
parentf3c6efd8d78f96a9a500b3ba7e024de122b9afa1 (diff)
downloadgoogletest-3c7bbf5b46679aea4e0ac7d3ad241cb036146751.zip
googletest-3c7bbf5b46679aea4e0ac7d3ad241cb036146751.tar.gz
googletest-3c7bbf5b46679aea4e0ac7d3ad241cb036146751.tar.bz2
Simplifies implementation by defining a POSIX portability layer; adds the death test style flag to --help.
Diffstat (limited to 'src/gtest-filepath.cc')
-rw-r--r--src/gtest-filepath.cc30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/gtest-filepath.cc b/src/gtest-filepath.cc
index d0cc5ff..7ba6a6b 100644
--- a/src/gtest-filepath.cc
+++ b/src/gtest-filepath.cc
@@ -33,22 +33,17 @@
#include <gtest/internal/gtest-port.h>
#include <stdlib.h>
-#include <string.h>
#ifdef _WIN32_WCE
#include <windows.h>
#elif GTEST_OS_WINDOWS
#include <direct.h>
#include <io.h>
-#include <sys/stat.h>
#elif GTEST_OS_SYMBIAN
// Symbian OpenC has PATH_MAX in sys/syslimits.h
#include <sys/syslimits.h>
-#include <unistd.h>
#else
#include <limits.h>
-#include <sys/stat.h> // NOLINT
-#include <unistd.h> // NOLINT
#include <climits> // Some Linux distributions define PATH_MAX here.
#endif // _WIN32_WCE or _WIN32
@@ -172,13 +167,9 @@ bool FilePath::FileOrDirectoryExists() const {
const DWORD attributes = GetFileAttributes(unicode);
delete [] unicode;
return attributes != kInvalidFileAttributes;
-#elif GTEST_OS_WINDOWS
- struct _stat file_stat = {};
- return _stat(pathname_.c_str(), &file_stat) == 0;
#else
- struct stat file_stat;
- memset(&file_stat, 0, sizeof(file_stat));
- return stat(pathname_.c_str(), &file_stat) == 0;
+ posix::stat_struct file_stat;
+ return posix::stat(pathname_.c_str(), &file_stat) == 0;
#endif // _WIN32_WCE
}
@@ -191,6 +182,10 @@ bool FilePath::DirectoryExists() const {
// Windows (like "C:\\").
const FilePath& path(IsRootDirectory() ? *this :
RemoveTrailingPathSeparator());
+#else
+ const FilePath& path(*this);
+#endif
+
#ifdef _WIN32_WCE
LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
const DWORD attributes = GetFileAttributes(unicode);
@@ -200,16 +195,11 @@ bool FilePath::DirectoryExists() const {
result = true;
}
#else
- struct _stat file_stat = {};
- result = _stat(path.c_str(), &file_stat) == 0 &&
- (_S_IFDIR & file_stat.st_mode) != 0;
+ posix::stat_struct file_stat;
+ result = posix::stat(path.c_str(), &file_stat) == 0 &&
+ posix::IsDir(file_stat);
#endif // _WIN32_WCE
-#else
- struct stat file_stat;
- memset(&file_stat, 0, sizeof(file_stat));
- result = stat(pathname_.c_str(), &file_stat) == 0 &&
- S_ISDIR(file_stat.st_mode);
-#endif // GTEST_OS_WINDOWS
+
return result;
}