summaryrefslogtreecommitdiffstats
path: root/src/disk_interface_test.cc
diff options
context:
space:
mode:
authorThiago Farina <tfarina@chromium.org>2011-09-08 00:23:33 (GMT)
committerThiago Farina <tfarina@chromium.org>2011-09-08 00:23:33 (GMT)
commit1e673c3af45ed7557e3dcee9c87107948a050016 (patch)
treefe7a88679ac10e9d5c73b77473b64f49d4138ee8 /src/disk_interface_test.cc
parent7a3dd0d534e7be3e8c8a57917e66c73b4e8a9ba0 (diff)
downloadNinja-1e673c3af45ed7557e3dcee9c87107948a050016.zip
Ninja-1e673c3af45ed7557e3dcee9c87107948a050016.tar.gz
Ninja-1e673c3af45ed7557e3dcee9c87107948a050016.tar.bz2
Fix windows build by moving mkdtemp() implementation from ninja_test.cc to disk_interface_test.cc
Signed-off-by: Thiago Farina <tfarina@chromium.org>
Diffstat (limited to 'src/disk_interface_test.cc')
-rw-r--r--src/disk_interface_test.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc
index ed26975..672d57c 100644
--- a/src/disk_interface_test.cc
+++ b/src/disk_interface_test.cc
@@ -25,6 +25,35 @@ using namespace std;
namespace {
+#ifdef _WIN32
+#ifndef _mktemp_s
+/// mingw has no mktemp. Implement one with the same type as the one
+/// found in the Windows API.
+int _mktemp_s(char* templ) {
+ char* ofs = strchr(templ, 'X');
+ sprintf(ofs, "%d", rand() % 1000000);
+ return 0;
+}
+#endif
+
+/// Windows has no mkdtemp. Implement it in terms of _mktemp_s.
+char* mkdtemp(char* name_template) {
+ int err = _mktemp_s(name_template);
+ if (err < 0) {
+ perror("_mktemp_s");
+ return NULL;
+ }
+
+ err = _mkdir(name_template);
+ if (err < 0) {
+ perror("mkdir");
+ return NULL;
+ }
+
+ return name_template;
+}
+#endif
+
class DiskInterfaceTest : public testing::Test {
public:
virtual void SetUp() {