From a0dca4df0c53ded97018098313eb9fda50a92690 Mon Sep 17 00:00:00 2001 From: Andreas Schuh Date: Mon, 17 Mar 2014 21:21:59 +0000 Subject: Create temporary directory for unit tests in specified --test_tmpdir if possible. --- src/util.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/util.h b/src/util.h index ce42082..0668fbc 100644 --- a/src/util.h +++ b/src/util.h @@ -237,23 +237,36 @@ class Test {}; #if defined(__MINGW32__) #include inline void MakeTmpdir(std::string* path) { + if (!path->empty()) { + path->append("/gflags_unittest_testdir"); + int err = mkdir(path->c_str()); + if (err == 0 || errno == EEXIST) return; + } // I had trouble creating a directory in /tmp from mingw - *path = "./gflags_unittest_testdir"; - mkdir(path->c_str()); // mingw has a weird one-arg mkdir + *path = "./gflags_unittest"; + mkdir(path->c_str()); } #elif defined(_MSC_VER) #include inline void MakeTmpdir(std::string* path) { + if (!path->empty()) { + int err = _mkdir(path->c_str()); + if (err == 0 || errno == EEXIST) return; + } char tmppath_buffer[1024]; int tmppath_len = GetTempPathA(sizeof(tmppath_buffer), tmppath_buffer); assert(tmppath_len > 0 && tmppath_len < sizeof(tmppath_buffer)); assert(tmppath_buffer[tmppath_len - 1] == '\\'); // API guarantees it - *path = std::string(tmppath_buffer) + "gflags_unittest_testdir"; + *path = std::string(tmppath_buffer) + "gflags_unittest"; _mkdir(path->c_str()); } #else inline void MakeTmpdir(std::string* path) { - mkdir(path->c_str(), 0755); + if (!path->empty()) { + int err = mkdir(path->c_str(), 0755); + if (err == 0 || errno == EEXIST) return; + } + mkdir("/tmp/gflags_unittest", 0755); } #endif -- cgit v1.2.3