36 #if GTEST_OS_WINDOWS_MOBILE
38 #elif GTEST_OS_WINDOWS
44 #endif // GTEST_OS_WINDOWS_MOBILE
49 # define GTEST_PATH_MAX_ _MAX_PATH
50 #elif defined(PATH_MAX)
51 # define GTEST_PATH_MAX_ PATH_MAX
52 #elif defined(_XOPEN_PATH_MAX)
53 # define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
55 # define GTEST_PATH_MAX_ _POSIX_PATH_MAX
56 #endif // GTEST_OS_WINDOWS
67 const char kAlternatePathSeparator =
'/';
68 const char kAlternatePathSeparatorString[] =
"/";
69 # if GTEST_OS_WINDOWS_MOBILE
75 const DWORD kInvalidFileAttributes = 0xffffffff;
78 # endif // GTEST_OS_WINDOWS_MOBILE
82 #endif // GTEST_OS_WINDOWS
86 #if GTEST_HAS_ALT_PATH_SEP_
95 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
99 #elif GTEST_OS_WINDOWS
101 return FilePath(_getcwd(cwd,
sizeof(cwd)) ==
nullptr ?
"" : cwd);
104 char* result = getcwd(cwd,
sizeof(cwd));
110 # endif // GTEST_OS_NACL
111 return FilePath(result ==
nullptr ?
"" : cwd);
112 #endif // GTEST_OS_WINDOWS_MOBILE
123 0, pathname_.length() - dot_extension.length()));
131 const char* FilePath::FindLastPathSeparator()
const {
133 #if GTEST_HAS_ALT_PATH_SEP_
134 const char*
const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);
136 if (last_alt_sep !=
nullptr &&
137 (last_sep ==
nullptr || last_alt_sep > last_sep)) {
150 FilePath FilePath::RemoveDirectoryName()
const {
151 const char*
const last_sep = FindLastPathSeparator();
152 return last_sep ?
FilePath(last_sep + 1) : *this;
161 FilePath FilePath::RemoveFileName()
const {
162 const char*
const last_sep = FindLastPathSeparator();
165 dir =
std::string(c_str(), last_sep + 1 - c_str());
184 file = base_name.string() +
"." +
extension;
189 return ConcatPaths(directory,
FilePath(file));
196 if (directory.IsEmpty())
197 return relative_path;
198 const FilePath dir(directory.RemoveTrailingPathSeparator());
204 bool FilePath::FileOrDirectoryExists()
const {
205 #if GTEST_OS_WINDOWS_MOBILE
206 LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
207 const DWORD attributes = GetFileAttributes(unicode);
209 return attributes != kInvalidFileAttributes;
212 return posix::Stat(pathname_.c_str(), &file_stat) == 0;
213 #endif // GTEST_OS_WINDOWS_MOBILE
218 bool FilePath::DirectoryExists()
const {
224 RemoveTrailingPathSeparator());
229 #if GTEST_OS_WINDOWS_MOBILE
230 LPCWSTR unicode = String::AnsiToUtf16(
path.c_str());
231 const DWORD attributes = GetFileAttributes(unicode);
233 if ((attributes != kInvalidFileAttributes) &&
234 (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
241 #endif // GTEST_OS_WINDOWS_MOBILE
248 bool FilePath::IsRootDirectory()
const {
250 return pathname_.length() == 3 && IsAbsolutePath();
252 return pathname_.length() == 1 &&
IsPathSeparator(pathname_.c_str()[0]);
257 bool FilePath::IsAbsolutePath()
const {
258 const char*
const name = pathname_.c_str();
260 return pathname_.length() >= 3 &&
261 ((
name[0] >=
'a' &&
name[0] <=
'z') ||
262 (
name[0] >=
'A' &&
name[0] <=
'Z')) &&
284 full_pathname.Set(MakeFileName(directory, base_name,
number++,
extension));
285 }
while (full_pathname.FileOrDirectoryExists());
286 return full_pathname;
292 bool FilePath::IsDirectory()
const {
293 return !pathname_.empty() &&
300 bool FilePath::CreateDirectoriesRecursively()
const {
301 if (!this->IsDirectory()) {
305 if (pathname_.length() == 0 || this->DirectoryExists()) {
309 const FilePath parent(this->RemoveTrailingPathSeparator().RemoveFileName());
310 return parent.CreateDirectoriesRecursively() && this->CreateFolder();
317 bool FilePath::CreateFolder()
const {
318 #if GTEST_OS_WINDOWS_MOBILE
319 FilePath removed_sep(this->RemoveTrailingPathSeparator());
320 LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
321 int result = CreateDirectory(unicode,
nullptr) ? 0 : -1;
323 #elif GTEST_OS_WINDOWS
324 int result = _mkdir(pathname_.c_str());
326 int result = mkdir(pathname_.c_str(), 0777);
327 #endif // GTEST_OS_WINDOWS_MOBILE
330 return this->DirectoryExists();
338 FilePath FilePath::RemoveTrailingPathSeparator()
const {
340 ?
FilePath(pathname_.substr(0, pathname_.length() - 1))
347 void FilePath::Normalize() {
348 if (pathname_.c_str() ==
nullptr) {
352 const char*
src = pathname_.c_str();
353 char*
const dest =
new char[pathname_.length() + 1];
354 char* dest_ptr =
dest;
355 memset(dest_ptr, 0, pathname_.length() + 1);
357 while (*
src !=
'\0') {
362 #if GTEST_HAS_ALT_PATH_SEP_
363 if (*dest_ptr == kAlternatePathSeparator) {