diff options
author | Andreas Schuh <andreas.schuh.84@gmail.com> | 2014-03-17 21:21:59 +0000 |
---|---|---|
committer | Andreas Schuh <andreas.schuh.84@gmail.com> | 2014-03-17 21:21:59 +0000 |
commit | a0dca4df0c53ded97018098313eb9fda50a92690 (patch) | |
tree | b21b00eb61c25c2965907fd6a7d67058a0334f42 | |
parent | eeb4db3234ecde76bd8351da9ad6318f3d40545e (diff) | |
download | gflags-a0dca4df0c53ded97018098313eb9fda50a92690.tar.gz gflags-a0dca4df0c53ded97018098313eb9fda50a92690.tar.bz2 gflags-a0dca4df0c53ded97018098313eb9fda50a92690.zip |
Create temporary directory for unit tests in specified --test_tmpdir if possible.
-rw-r--r-- | src/util.h | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -237,23 +237,36 @@ class Test {}; #if defined(__MINGW32__) #include <io.h> 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 <direct.h> 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 |