36#if GTEST_OS_WINDOWS_MOBILE
43# include <sys/syslimits.h>
52# define GTEST_PATH_MAX_ _MAX_PATH
53#elif defined(PATH_MAX)
54# define GTEST_PATH_MAX_ PATH_MAX
55#elif defined(_XOPEN_PATH_MAX)
56# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
58# define GTEST_PATH_MAX_ _POSIX_PATH_MAX
70const char kAlternatePathSeparator =
'/';
71const char kAlternatePathSeparatorString[] =
"/";
72# if GTEST_OS_WINDOWS_MOBILE
78const DWORD kInvalidFileAttributes = 0xffffffff;
88static bool IsPathSeparator(
char c) {
89#if GTEST_HAS_ALT_PATH_SEP_
98#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
102#elif GTEST_OS_WINDOWS
107 char* result = getcwd(
cwd,
sizeof(
cwd));
123 const std::string dot_extension = std::string(
".") + extension;
126 0, pathname_.length() - dot_extension.length()));
134const char* FilePath::FindLastPathSeparator()
const {
136#if GTEST_HAS_ALT_PATH_SEP_
137 const char*
const last_alt_sep = strrchr(
c_str(), kAlternatePathSeparator);
139 if (last_alt_sep != NULL &&
140 (last_sep == NULL || last_alt_sep > last_sep)) {
154 const char*
const last_sep = FindLastPathSeparator();
155 return last_sep ?
FilePath(last_sep + 1) : *
this;
165 const char*
const last_sep = FindLastPathSeparator();
168 dir = std::string(
c_str(), last_sep + 1 -
c_str());
184 const char* extension) {
187 file = base_name.
string() +
"." + extension;
199 if (directory.IsEmpty())
200 return relative_path;
201 const FilePath dir(directory.RemoveTrailingPathSeparator());
208#if GTEST_OS_WINDOWS_MOBILE
209 LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
210 const DWORD attributes = GetFileAttributes(unicode);
212 return attributes != kInvalidFileAttributes;
215 return posix::Stat(pathname_.c_str(), &file_stat) == 0;
232#if GTEST_OS_WINDOWS_MOBILE
233 LPCWSTR unicode = String::AnsiToUtf16(path.
c_str());
234 const DWORD attributes = GetFileAttributes(unicode);
236 if ((attributes != kInvalidFileAttributes) &&
237 (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
258 return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
264 const char*
const name = pathname_.c_str();
266 return pathname_.length() >= 3 &&
267 ((
name[0] >=
'a' &&
name[0] <=
'z') ||
268 (
name[0] >=
'A' &&
name[0] <=
'Z')) &&
270 IsPathSeparator(
name[2]);
272 return IsPathSeparator(
name[0]);
286 const char* extension) {
290 full_pathname.
Set(
MakeFileName(directory, base_name, number++, extension));
292 return full_pathname;
299 return !pathname_.empty() &&
300 IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]);
311 if (pathname_.length() == 0 || this->DirectoryExists()) {
324#if GTEST_OS_WINDOWS_MOBILE
326 LPCWSTR unicode = String::AnsiToUtf16(removed_sep.
c_str());
327 int result = CreateDirectory(unicode, NULL) ? 0 : -1;
329#elif GTEST_OS_WINDOWS
330 int result = _mkdir(pathname_.c_str());
332 int result = mkdir(pathname_.c_str(), 0777);
346 ?
FilePath(pathname_.substr(0, pathname_.length() - 1))
354void FilePath::Normalize() {
355 if (pathname_.c_str() == NULL) {
359 const char* src = pathname_.c_str();
360 char*
const dest =
new char[pathname_.length() + 1];
361 char* dest_ptr = dest;
362 memset(dest_ptr, 0, pathname_.length() + 1);
364 while (*src !=
'\0') {
366 if (!IsPathSeparator(*src)) {
369#if GTEST_HAS_ALT_PATH_SEP_
370 if (*dest_ptr == kAlternatePathSeparator) {
374 while (IsPathSeparator(*src))
bool IsRootDirectory() const
bool FileOrDirectoryExists() const
void Set(const FilePath &rhs)
static FilePath GenerateUniqueFileName(const FilePath &directory, const FilePath &base_name, const char *extension)
bool CreateDirectoriesRecursively() const
const std::string & string() const
FilePath RemoveFileName() const
const char * c_str() const
FilePath RemoveDirectoryName() const
bool DirectoryExists() const
static FilePath MakeFileName(const FilePath &directory, const FilePath &base_name, int number, const char *extension)
FilePath RemoveExtension(const char *extension) const
static FilePath GetCurrentDir()
FilePath RemoveTrailingPathSeparator() const
static FilePath ConcatPaths(const FilePath &directory, const FilePath &relative_path)
bool IsAbsolutePath() const
bool CreateFolder() const
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
int Stat(const char *path, StatStruct *buf)
bool IsDir(const StatStruct &st)
const char kCurrentDirectoryString[]
std::string StreamableToString(const T &streamable)
const char kPathSeparator
memset(pInfo->slotDescription, ' ', 64)