Index: tests/support.c
===================================================================
--- tests/support.c	(revision 5870)
+++ tests/support.c	(working copy)
@@ -1,27 +1,113 @@
 #include "support.h"
 
+#ifdef WIN32
+
+/*  Testing of vformat requires a temporary directory.
+ *  On Windows, there is no mkdtemp,
+ *  and GLib only provides g_mkstemp.
+ *  Hence we have to define our own version of mkdtemp.
+ *  The code below is based on g_mkstemp_full from GLib.
+ *  Copyright 2000 Red Hat, Inc.
+ */
+
+#include <errno.h>
+gint
+mkdtemp_full (gchar *tmpl, 
+		int    mode)
+{
+  char *XXXXXX;
+  int count, fd;
+  static const char letters[] =
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+  static const int NLETTERS = sizeof (letters) - 1;
+  glong value;
+  GTimeVal tv;
+  static int counter = 0;
+
+  g_return_val_if_fail (tmpl != NULL, -1);
+
+
+  /* find the last occurrence of "XXXXXX" */
+  XXXXXX = g_strrstr (tmpl, "XXXXXX");
+
+  if (!XXXXXX || strncmp (XXXXXX, "XXXXXX", 6))
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  /* Get some more or less random data.  */
+  g_get_current_time (&tv);
+  value = (tv.tv_usec ^ tv.tv_sec) + counter++;
+
+  for (count = 0; count < 100; value += 7777, ++count)
+    {
+      glong v = value;
+
+      /* Fill in the random bits.  */
+      XXXXXX[0] = letters[v % NLETTERS];
+      v /= NLETTERS;
+      XXXXXX[1] = letters[v % NLETTERS];
+      v /= NLETTERS;
+      XXXXXX[2] = letters[v % NLETTERS];
+      v /= NLETTERS;
+      XXXXXX[3] = letters[v % NLETTERS];
+      v /= NLETTERS;
+      XXXXXX[4] = letters[v % NLETTERS];
+      v /= NLETTERS;
+      XXXXXX[5] = letters[v % NLETTERS];
+
+      /* tmpl is in UTF-8 on Windows, thus use g_open() */
+      fd = g_mkdir (tmpl, mode);
+
+      if (fd >= 0)
+	return fd;
+      else if (errno != EEXIST)
+	/* Any other error will apply also to other names we might
+	 *  try, and there are 2^32 or so of them, so give up now.
+	 */
+	return -1;
+    }
+
+  /* We got out of the loop because we ran out of combinations to try.  */
+  errno = EEXIST;
+  return -1;
+}
+
+gint
+mkdtemp (gchar *tmpl)
+{
+  return mkdtemp_full (tmpl, 0700);
+}
+
+#endif
+
+// ------------------------------------------------------------
+
 char *olddir = NULL;
 
 static void reset_env(void)
 {
-	unsetenv("CONNECT_ERROR");
-	unsetenv("CONNECT_TIMEOUT");
-	unsetenv("INIT_NULL");
-	unsetenv("GET_CHANGES_ERROR");
-	unsetenv("GET_CHANGES_TIMEOUT");
-	unsetenv("GET_CHANGES_TIMEOUT2");
-	unsetenv("COMMIT_ERROR");
-	unsetenv("COMMIT_TIMEOUT");
-	unsetenv("SYNC_DONE_ERROR");
-	unsetenv("SYNC_DONE_TIMEOUT");
-	unsetenv("DISCONNECT_ERROR");
-	unsetenv("DISCONNECT_TIMEOUT");
+	g_unsetenv("CONNECT_ERROR");
+	g_unsetenv("CONNECT_TIMEOUT");
+	g_unsetenv("INIT_NULL");
+	g_unsetenv("GET_CHANGES_ERROR");
+	g_unsetenv("GET_CHANGES_TIMEOUT");
+	g_unsetenv("GET_CHANGES_TIMEOUT2");
+	g_unsetenv("COMMIT_ERROR");
+	g_unsetenv("COMMIT_TIMEOUT");
+	g_unsetenv("SYNC_DONE_ERROR");
+	g_unsetenv("SYNC_DONE_TIMEOUT");
+	g_unsetenv("DISCONNECT_ERROR");
+	g_unsetenv("DISCONNECT_TIMEOUT");
 }
-
 char *setup_testbed(char *fkt_name)
 {
 	
+#ifndef WIN32
+	// Run testbed as "nobody"
 	setuid(65534);
+#endif
 	char *testbed = g_strdup_printf("%s/testbed.XXXXXX", g_get_tmp_dir());
 	mkdtemp(testbed);
 	

