Index: ChangeLog
===================================================================
--- ChangeLog	(revision 6768)
+++ ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2008-03-28  Jeffrey Stedfast  <fejj@novell.com>
+
+	* glib/gfileutils.c (g_mkdtemp): New convenience function
+	implementing a similar function as mkdtemp() on some UNIX
+	platforms.
+
 2008-03-22  Claudio Saavedra  <csaavedra@gnome.org>
 
 	Bug 523877 – gbookmarkfile: avoid using g_string_append_printf() and
Index: glib/gfileutils.c
===================================================================
--- glib/gfileutils.c	(revision 6768)
+++ glib/gfileutils.c	(working copy)
@@ -1223,6 +1223,84 @@
   return create_temp_file (tmpl, 0600);
 }
 
+/**
+ * g_mkdtemp:
+ * @tmpl: template directory name
+ *
+ * Creates a temporary directory. See the mkdtemp() documentation
+ * on most UNIX-like systems. 
+ *
+ * The parameter is a string that should follow the rules for
+ * mkdtemp() templates, i.e. contain the string "XXXXXX".  g_mkdtemp()
+ * is slightly more flexible than mkdtemp() in that the sequence does
+ * not have to occur at the very end of the template. The X string
+ * will be modified to form the name of a directory that didn't
+ * already exist.  The string should be in the GLib file name
+ * encoding. Most importantly, on Windows it should be in UTF-8.
+ *
+ * Return value: If a temporary directory was successfully created,
+ * @tmpl will be returned with the XXXXXX string modified in such a
+ * way as to make the path unique.  In case of errors, %NULL is
+ * returned.
+ */ 
+gchar *
+g_mkdtemp (gchar *tmpl)
+{
+  static const char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+  static const int NLETTERS = sizeof (letters) - 1;
+  static int counter = 0;
+  char *XXXXXX, *p;
+  GTimeVal tv;
+  glong value;
+  int count;
+  int rv;
+  
+  /* find the last occurrence of "XXXXXX" */
+  XXXXXX = g_strrstr (tmpl, "XXXXXX");
+  
+  if (!XXXXXX || strncmp (XXXXXX, "XXXXXX", 6))
+    {
+      errno = EINVAL;
+      return NULL;
+    }
+  
+  /* 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_mkdir() */
+      if (g_mkdir (tmpl, 0700) == 0)
+        return tmpl;
+      
+      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 NULL;
+    }
+  
+  /* We got out of the loop because we ran out of combinations to try.  */
+  errno = EEXIST;
+  return NULL;
+}
+
 #ifdef G_OS_WIN32
 
 #undef g_mkstemp
Index: glib/gfileutils.h
===================================================================
--- glib/gfileutils.h	(revision 6768)
+++ glib/gfileutils.h	(working copy)
@@ -100,6 +100,9 @@
 /* Wrapper / workalike for mkstemp() */
 gint    g_mkstemp            (gchar        *tmpl);
 
+/* Wrapper / workalike for mkdtemp() */
+gchar  *g_mkdtemp            (gchar        *tmpl);
+
 /* Wrapper for g_mkstemp */
 gint    g_file_open_tmp      (const gchar  *tmpl,
 			      gchar       **name_used,
