summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-09-08 02:51:29 (GMT)
committerEvan Martin <martine@danga.com>2011-09-08 02:51:29 (GMT)
commitf782babf8f943725b68f0e26cfbeaedbabe77477 (patch)
tree58b11d93043b440130a93cf98b93bfa70f68fcbc /src
parente0fb5ba60bb7c3a9f4e4a4e5ea6a16f1010cb59e (diff)
parent1e673c3af45ed7557e3dcee9c87107948a050016 (diff)
downloadNinja-f782babf8f943725b68f0e26cfbeaedbabe77477.zip
Ninja-f782babf8f943725b68f0e26cfbeaedbabe77477.tar.gz
Ninja-f782babf8f943725b68f0e26cfbeaedbabe77477.tar.bz2
Merge pull request #98 from tfarina/fix-win-build
Fix windows build by moving mkdtemp() implementation from ninja_test.cc t
Diffstat (limited to 'src')
-rw-r--r--src/disk_interface_test.cc29
-rw-r--r--src/ninja_test.cc28
2 files changed, 29 insertions, 28 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() {
diff --git a/src/ninja_test.cc b/src/ninja_test.cc
index 2ccc151..c1999d9 100644
--- a/src/ninja_test.cc
+++ b/src/ninja_test.cc
@@ -211,32 +211,4 @@ TEST_F(StatTest, Middle) {
ASSERT_TRUE(GetNode("out")->dirty_);
}
-#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