diff options
author | Matthew Woehlke <matthew.woehlke@kitware.com> | 2022-08-17 18:20:47 (GMT) |
---|---|---|
committer | Matthew Woehlke <matthew.woehlke@kitware.com> | 2022-09-05 17:19:58 (GMT) |
commit | d1befe5515968d7fe4f7fd3f2ca243e98d6012d0 (patch) | |
tree | f60ecc3aced197ff90d2d2d2d3705cd3178818a1 /Source/cmSystemTools.h | |
parent | 7b9757e50715ab6abc08e7005c66565f5c965de3 (diff) | |
download | CMake-d1befe5515968d7fe4f7fd3f2ca243e98d6012d0.zip CMake-d1befe5515968d7fe4f7fd3f2ca243e98d6012d0.tar.gz CMake-d1befe5515968d7fe4f7fd3f2ca243e98d6012d0.tar.bz2 |
cmSystemTools: Add MakeTempDirectory
Add a cross-platform wrapper over mkdtemp. This will allow us to create
guaranteed-unique directories. On POSIX platforms, this is simply a
wrapper over mkdtemp. On Windows, we take a brute-force approach using
C++11's random facilities and relying on attempts to create an existing
directory resulting in an error. (This approach is very possibly how
mkdtemp is implemented internally, and should be suitable for any
platform if needed, although at present it only uses a partial set of
substitution characters since Windows likely implies a case-insensitive
file system.)
Diffstat (limited to 'Source/cmSystemTools.h')
-rw-r--r-- | Source/cmSystemTools.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 48bbe23..b02a977 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -4,6 +4,10 @@ #include "cmConfigure.h" // IWYU pragma: keep +#if !defined(_WIN32) +# include <sys/types.h> +#endif + #include <cstddef> #include <functional> #include <map> @@ -151,6 +155,27 @@ public: Failure, }; +#if defined(_MSC_VER) + /** Visual C++ does not define mode_t. */ + using mode_t = unsigned short; +#endif + + /** + * Make a new temporary directory. The path must end in "XXXXXX", and will + * be modified to reflect the name of the directory created. This function + * is similar to POSIX mkdtemp (and is implemented using the same where that + * function is available). + * + * This function can make a full path even if none of the directories existed + * prior to calling this function. + * + * Note that this function may modify \p path even if it does not succeed. + */ + static cmsys::Status MakeTempDirectory(char* path, + const mode_t* mode = nullptr); + static cmsys::Status MakeTempDirectory(std::string& path, + const mode_t* mode = nullptr); + /** Copy a file. */ static bool CopySingleFile(const std::string& oldname, const std::string& newname); |