Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.336.2.22
diff -u -r1.336.2.22 configure.in
--- configure.in	12 Jul 2003 16:18:50 -0000	1.336.2.22
+++ configure.in	29 Jul 2003 09:41:51 -0000
@@ -691,7 +691,7 @@
 AC_MSG_RESULT(unsigned $glib_size_type)
 
 # Check for some functions
-AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep vasprintf unsetenv getc_unlocked)
+AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp mkdtemp vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep vasprintf unsetenv getc_unlocked)
 
 AC_FUNC_VSNPRINTF_C99
 AC_FUNC_PRINTF_UNIX98
Index: glib/gfileutils.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gfileutils.c,v
retrieving revision 1.37
diff -u -r1.37 gfileutils.c
--- glib/gfileutils.c	11 Dec 2002 23:40:09 -0000	1.37
+++ glib/gfileutils.c	29 Jul 2003 09:41:51 -0000
@@ -714,6 +714,82 @@
 }
 
 /**
+ * g_mkdtemp:
+ * @tmpl: template dirname
+ *
+ * Creates a temporary folder. See the <function>mkdtemp()</function> 
+ * documentation on glibc-based UNIX-like systems. This is a portability
+ * wrapper, which simply calls <function>mkdtemp()</function> on systems
+ *  that have it, and implements it in GLib otherwise.
+ *
+ * The parameter is a string that should match the rules for
+ * <function>mkdtemp()</function>, i.e. end in "XXXXXX". The X string will 
+ * be modified to form the name of a directory that didn't exist.
+ *
+ * Return value: The (as from <function>mkdtemp()</function>) name
+ * of the created folder. In case of errors, NULL is returned.
+ */
+char *
+g_mkdtemp (char *tmpl)
+{
+#ifdef HAVE_MKDTEMP
+  return mkdtemp (tmpl);
+#else
+  int len;
+  char *XXXXXX;
+  int count;
+  static const char letters[] =
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+  static const int NLETTERS = sizeof (letters) - 1;
+  glong value;
+  GTimeVal tv;
+  static int counter = 0;
+
+  len = strlen (tmpl);
+  if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
+    return NULL;
+
+  /* This is where the Xs start.  */
+  XXXXXX = &tmpl[len - 6];
+
+  /* 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];
+
+      if (mkdir (tmpl, 0700)) {
+        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;
+      } else {
+        return tmpl;
+      }
+    }
+
+  /* We got out of the loop because we ran out of combinations to try.  */
+  return NULL;
+#endif
+}
+
+/**
  * g_file_open_tmp:
  * @tmpl: Template for file name, as in g_mkstemp(), basename only
  * @name_used: location to store actual name used
Index: glib/gfileutils.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gfileutils.h,v
retrieving revision 1.9
diff -u -r1.9 gfileutils.h
--- glib/gfileutils.h	10 Sep 2001 13:30:40 -0000	1.9
+++ glib/gfileutils.h	29 Jul 2003 09:41:51 -0000
@@ -83,6 +83,9 @@
 /* Wrapper / workalike for mkstemp() */
 int     g_mkstemp            (char         *tmpl);
 
+/* Wrapper / workalike for mkdtemp() */
+char   *g_mkdtemp            (char         *tmpl);
+
 /* Wrapper for g_mkstemp */
 int     g_file_open_tmp      (const char   *tmpl,
 			      char        **name_used,
