diff --git a/glib/gfileutils.c b/glib/gfileutils.c
index 76335fa..1532826 100644
--- a/glib/gfileutils.c
+++ b/glib/gfileutils.c
@@ -1148,65 +1148,32 @@ g_file_set_contents (const gchar  *filename,
   return retval;
 }
 
-/**
- * g_mkstemp_full:
- * @tmpl: template filename
- * @flags: flags to pass to an open() call in addition to O_EXCL and
- *         O_CREAT, which are passed automatically
- * @mode: permissios to create the temporary file with
- *
- * Opens a temporary file. See the mkstemp() documentation
- * on most UNIX-like systems.
- *
- * The parameter is a string that should follow the rules for
- * mkstemp() templates, i.e. contain the string "XXXXXX".
- * g_mkstemp_full() is slightly more flexible than mkstemp()
- * in that the sequence does not have to occur at the very end of the
- * template and you can pass a @mode and additional @flags. The X
- * string will be modified to form the name of a file that didn't exist.
- * The string should be in the GLib file name encoding. Most importantly,
- * on Windows it should be in UTF-8.
- *
- * Return value: A file handle (as from open()) to the file
- *     opened for reading and writing. The file handle should be
- *     closed with close(). In case of errors, -1 is returned.
- *
- * Since: 2.22
- */
-/*
- * g_mkstemp_full based on the mkstemp implementation from the GNU C library.
- * Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
- */
-gint
-g_mkstemp_full (gchar *tmpl, 
-                int    flags,
-		int    mode)
+typedef enum { MAKE_DIR, MAKE_FILE } make_t;
+
+static int
+g_mktemp (gchar *tmpl, make_t make, int flags, int mode)
 {
-  char *XXXXXX;
-  int count, fd;
-  static const char letters[] =
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+  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);
-
+  int count, rv;
+  char *XXXXXX;
+  GTimeVal tv;
+  glong value;
 
   /* find the last occurrence of "XXXXXX" */
   XXXXXX = g_strrstr (tmpl, "XXXXXX");
-
-  if (!XXXXXX || strncmp (XXXXXX, "XXXXXX", 6))
+  
+  if (!XXXXXX)
     {
       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;
@@ -1224,12 +1191,15 @@ g_mkstemp_full (gchar *tmpl,
       v /= NLETTERS;
       XXXXXX[5] = letters[v % NLETTERS];
 
-      /* tmpl is in UTF-8 on Windows, thus use g_open() */
-      fd = g_open (tmpl, flags | O_CREAT | O_EXCL, mode);
+      if (make == MAKE_FILE)
+        rv = g_open (tmpl, flags | O_CREAT | O_EXCL, mode);
+      else
+        rv = g_mkdir (tmpl, mode);
 
-      if (fd >= 0)
-	return fd;
-      else if (errno != EEXIST)
+      if (rv >= 0)
+        return rv;
+
+      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.
 	 */
@@ -1242,6 +1212,45 @@ g_mkstemp_full (gchar *tmpl,
 }
 
 /**
+ * g_mkstemp_full:
+ * @tmpl: template filename
+ * @flags: flags to pass to an open() call in addition to O_EXCL and
+ *         O_CREAT, which are passed automatically
+ * @mode: permissios to create the temporary file with
+ *
+ * Opens a temporary file. See the mkstemp() documentation
+ * on most UNIX-like systems.
+ *
+ * The parameter is a string that should follow the rules for
+ * mkstemp() templates, i.e. contain the string "XXXXXX".
+ * g_mkstemp_full() is slightly more flexible than mkstemp()
+ * in that the sequence does not have to occur at the very end of the
+ * template and you can pass a @mode and additional @flags. The X
+ * string will be modified to form the name of a file that didn't exist.
+ * The string should be in the GLib file name encoding. Most importantly,
+ * on Windows it should be in UTF-8.
+ *
+ * Return value: A file handle (as from open()) to the file
+ *     opened for reading and writing. The file handle should be
+ *     closed with close(). In case of errors, -1 is returned.
+ *
+ * Since: 2.22
+ */
+/*
+ * g_mkstemp_full based on the mkstemp implementation from the GNU C library.
+ * Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
+ */
+gint
+g_mkstemp_full (gchar *tmpl, 
+                int    flags,
+		int    mode)
+{
+  g_return_val_if_fail (tmpl != NULL, -1);
+
+  return g_mktemp (tmpl, MAKE_FILE, flags, mode);
+}
+
+/**
  * g_mkstemp:
  * @tmpl: template filename
  *
@@ -1265,7 +1274,9 @@ g_mkstemp_full (gchar *tmpl,
 gint
 g_mkstemp (gchar *tmpl)
 {
-  return g_mkstemp_full (tmpl, O_RDWR | O_BINARY, 0600);
+  g_return_val_if_fail (tmpl != NULL, -1);
+
+  return g_mktemp (tmpl, MAKE_FILE, O_RDWR | O_BINARY, 0600);
 }
 
 /**
@@ -1558,6 +1569,34 @@ g_build_path (const gchar *separator,
   return str;
 }
 
+/**
+ * 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)
+{
+  g_return_val_if_fail (tmpl != NULL, NULL);
+
+  return g_mktemp (tmpl, MAKE_DIR, 0, 0700) == 0 ? tmpl : NULL;
+}
+
 #ifdef G_OS_WIN32
 
 static gchar *
diff --git a/glib/gfileutils.h b/glib/gfileutils.h
index d8f9d3b..c6c04b7 100644
--- a/glib/gfileutils.h
+++ b/glib/gfileutils.h
@@ -103,6 +103,9 @@ gint    g_mkstemp_full       (gchar        *tmpl,
                               int           flags,
                               int           mode);
 
+/* Wrapper / workalike for mkdtemp() */
+gchar  *g_mkdtemp            (gchar        *tmpl);
+
 /* Wrapper for g_mkstemp */
 gint    g_file_open_tmp      (const gchar  *tmpl,
 			      gchar       **name_used,
