diff options
author | Tim Rowley <[email protected]> | 2017-04-26 13:46:31 -0500 |
---|---|---|
committer | Tim Rowley <[email protected]> | 2017-05-30 17:20:33 -0500 |
commit | 7e35777624aa2fd3c27f8effb5d070d4804c5ee6 (patch) | |
tree | 383685971625ec2e251f758549a67084f2813762 /src/gallium/drivers/swr/rasterizer/common | |
parent | f094d582ece128eb66157d1058f6093bef743054 (diff) |
swr/rast: add CreateDirectoryPath to recursively create directories
Reviewed-by: Bruce Cherniak <[email protected]>
Diffstat (limited to 'src/gallium/drivers/swr/rasterizer/common')
-rw-r--r-- | src/gallium/drivers/swr/rasterizer/common/os.cpp | 48 | ||||
-rw-r--r-- | src/gallium/drivers/swr/rasterizer/common/os.h | 3 |
2 files changed, 48 insertions, 3 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/common/os.cpp b/src/gallium/drivers/swr/rasterizer/common/os.cpp index 295556a5678..27ad5e90b66 100644 --- a/src/gallium/drivers/swr/rasterizer/common/os.cpp +++ b/src/gallium/drivers/swr/rasterizer/common/os.cpp @@ -22,8 +22,14 @@ ****************************************************************************/ #include "common/os.h" +#include <vector> +#include <sstream> -#if defined(FORCE_LINUX) || defined(__linux__) || defined(__gnu_linux__) +#if defined(_WIN32) +#include <shlobj.h> +#endif // Windows + +#if defined(__APPLE__) || defined(FORCE_LINUX) || defined(__linux__) || defined(__gnu_linux__) #include <pthread.h> #endif // Linux @@ -105,3 +111,43 @@ void SWR_API SetCurrentThreadName(const char* pThreadName) pthread_setname_np(pthread_self(), pThreadName); #endif // Linux } + +static void SplitString(std::vector<std::string>& out_segments, const std::string& input, char splitToken) +{ + out_segments.clear(); + + std::istringstream f(input); + std::string s; + while (std::getline(f, s, splitToken)) + { + if (s.size()) + { + out_segments.push_back(s); + } + } +} + +void SWR_API CreateDirectoryPath(const std::string& path) +{ +#if defined(_WIN32) + SHCreateDirectoryExA(nullptr, path.c_str(), nullptr); +#endif // Windows + +#if defined(__APPLE__) || defined(FORCE_LINUX) || defined(__linux__) || defined(__gnu_linux__) + std::vector<std::string> pathSegments; + SplitString(pathSegments, path, '/'); + + std::string tmpPath; + for (auto const& segment : pathSegments) + { + tmpPath.push_back('/'); + tmpPath += segment; + + int result = mkdir(tmpPath.c_str(), 0777); + if (result == -1 && errno != EEXIST) + { + break; + } + } +#endif // Unix +} diff --git a/src/gallium/drivers/swr/rasterizer/common/os.h b/src/gallium/drivers/swr/rasterizer/common/os.h index f9b6ccaee82..6e4d98f13fc 100644 --- a/src/gallium/drivers/swr/rasterizer/common/os.h +++ b/src/gallium/drivers/swr/rasterizer/common/os.h @@ -234,8 +234,6 @@ void AlignedFree(void* p) pid_t gettid(void); #define GetCurrentThreadId gettid -#define CreateDirectory(name, pSecurity) mkdir(name, 0777) - #define InterlockedCompareExchange(Dest, Exchange, Comparand) __sync_val_compare_and_swap(Dest, Comparand, Exchange) #define InterlockedExchangeAdd(Addend, Value) __sync_fetch_and_add(Addend, Value) #define InterlockedDecrement(Append) __sync_sub_and_fetch(Append, 1) @@ -281,5 +279,6 @@ typedef MEGABYTE GIGABYTE[1024]; // Defined in os.cpp void SWR_API SetCurrentThreadName(const char* pThreadName); +void SWR_API CreateDirectoryPath(const std::string& path); #endif//__SWR_OS_H__ |