diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-io.cpp | 43 | ||||
| -rw-r--r-- | source/core/slang-io.h | 2 |
2 files changed, 45 insertions, 0 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index ab093f577..2b443a62b 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -132,6 +132,49 @@ namespace Slang #endif } + /* static */SlangResult Path::GetPathType(const String & path, SlangPathType* pathTypeOut) + { +#ifdef _WIN32 + // https://msdn.microsoft.com/en-us/library/14h5k7ff.aspx + struct _stat32 statVar; + if (::_wstat32(String(path).ToWString(), &statVar) == 0) + { + if (statVar.st_mode & _S_IFDIR) + { + *pathTypeOut = SLANG_PATH_TYPE_DIRECTORY; + return SLANG_OK; + } + else if (statVar.st_mode & _S_IFREG) + { + *pathTypeOut = SLANG_PATH_TYPE_FILE; + return SLANG_OK; + } + return SLANG_FAIL; + } + + return SLANG_E_NOT_FOUND; +#else + struct stat statVar; + if (::stat(path.Buffer(), &statVar) == 0) + { + if (S_ISDIR(statVar.st_mode)) + { + *pathTypeOut = SLANG_PATH_TYPE_DIRECTORY; + return SLANG_OK; + } + if (S_ISREG(statVar.st_mode)) + { + *pathTypeOut = SLANG_PATH_TYPE_FILE; + return SLANG_OK; + } + return SLANG_FAIL; + } + + return SLANG_E_NOT_FOUND; +#endif + } + + /* static */SlangResult Path::GetCanonical(const String & path, String & canonicalPathOut) { #if defined(_WIN32) diff --git a/source/core/slang-io.h b/source/core/slang-io.h index 543b12adf..ff287254c 100644 --- a/source/core/slang-io.h +++ b/source/core/slang-io.h @@ -32,6 +32,8 @@ namespace Slang static String Combine(const String & path1, const String & path2, const String & path3); static bool CreateDir(const String & path); + static SlangResult GetPathType(const String & path, SlangPathType* pathTypeOut); + static SlangResult GetCanonical(const String & path, String& canonicalPathOut); }; } |
