17 #ifndef __STOUT_OS_WINDOWS_MKDTEMP_HPP__ 18 #define __STOUT_OS_WINDOWS_MKDTEMP_HPP__ 46 static const char postfixTemplate[] =
"XXXXXX";
47 static const size_t postfixSize =
sizeof(postfixTemplate) - 1;
51 "Invalid template passed to `os::mkdtemp`: template '" +
path +
52 "' should end with 6 'X' characters");
55 static const char alphabet[] =
57 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 58 "abcdefghijklmnopqrstuvwxyz";
64 static const size_t maxAlphabetIndex =
sizeof(alphabet) - 2;
66 std::string postfix(postfixTemplate);
67 static thread_local std::mt19937 generator((std::random_device())());
69 for (
int i = 0; i < postfixSize; ++i) {
70 int index = generator() % maxAlphabetIndex;
71 postfix[i] = alphabet[
index];
75 std::string tempPath =
path 76 .substr(0,
path.length() - postfixSize)
91 #endif // __STOUT_OS_WINDOWS_MKDTEMP_HPP__ bool endsWith(const std::string &s, const std::string &suffix)
Definition: strings.hpp:402
Definition: errorbase.hpp:36
Definition: posix_signalhandler.hpp:23
std::string join(const std::string &path1, const std::string &path2, const char _separator=os::PATH_SEPARATOR)
Definition: path.hpp:116
Result< int > index(const std::string &link)
Try< Nothing > mkdir(const std::string &directory, bool recursive=true, bool sync=false)
Definition: mkdir.hpp:42
Try< Nothing > append(const std::string &path, const google::protobuf::Message &message, bool sync=false)
Definition: protobuf.hpp:174
static Try error(const E &e)
Definition: try.hpp:43
bool isError() const
Definition: try.hpp:78
std::string temp()
Definition: temp.hpp:27
Try< std::string > mkdtemp(const std::string &path=path::join(os::temp(),"XXXXXX"))
Definition: mkdtemp.hpp:38