Fix windows build by moving mkdtemp() implementation from ninja_test.cc to disk_inter...
authorThiago Farina <tfarina@chromium.org>
Thu, 8 Sep 2011 00:23:33 +0000 (21:23 -0300)
committerThiago Farina <tfarina@chromium.org>
Thu, 8 Sep 2011 00:23:33 +0000 (21:23 -0300)
Signed-off-by: Thiago Farina <tfarina@chromium.org>
src/disk_interface_test.cc
src/ninja_test.cc

index ed26975..672d57c 100644 (file)
@@ -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() {
index 2ccc151..c1999d9 100644 (file)
@@ -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