-LRN: fix mkdtemp on W32
authorChristian Grothoff <christian@grothoff.org>
Sun, 10 Jun 2012 22:41:48 +0000 (22:41 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 10 Jun 2012 22:41:48 +0000 (22:41 +0000)
src/util/disk.c

index 3705e1be2e53ac31cf2dda1cce0f540c1ee37bd7..ecd361ba138cbad7722b5a93199a8145e29694a5 100644 (file)
@@ -440,6 +440,36 @@ mktemp_name (const char *t)
   return fn;
 }
 
+#if WINDOWS
+static char *
+mkdtemp (char *fn)
+{
+  char *random_fn;
+  char *tfn;
+  while (1)
+  {
+    tfn = GNUNET_strdup (fn);
+    random_fn = _mktemp (tfn);
+    if (NULL == random_fn)
+    {
+      GNUNET_free (tfn);
+      return NULL;
+    }
+    /* FIXME: assume fn to be UTF-8-encoded and do the right thing */
+    if (0 == CreateDirectoryA (tfn, NULL))
+    {
+      DWORD error = GetLastError ();
+      GNUNET_free (tfn);
+      if (ERROR_ALREADY_EXISTS == error)
+        continue;
+      return NULL;
+    }
+    break;
+  }
+  strcpy (fn, tfn);
+  return fn;
+}
+#endif
 
 /**
  * Create an (empty) temporary directory on disk.  If the given name is not