diff --git a/gio/gfile.c b/gio/gfile.c
index 86111d2..cd33d1d 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -67,6 +67,7 @@
  * g_file_new_for_path() if you have a path.
  * g_file_new_for_uri() if you have a URI.
  * g_file_new_for_commandline_arg() for a command line argument.
+ * g_file_new_for_temp() if you have a template for temporary file.
  * g_file_parse_name() from a utf8 string gotten from g_file_get_parse_name().
  * 
  * One way to think of a #GFile is as an abstraction of a pathname. For normal
@@ -5973,6 +5974,45 @@ g_file_new_for_commandline_arg (const char *arg)
 }
 
 /**
+ * g_file_new_for_temp:
+ * @tmpl: Template for file name, as in g_mkstemp(), basename only.
+ *
+ * Constructs a #GFile for a temporary file using the given template.
+ * The template should be a string in the GLib file name encoding containing a
+ * sequence of six 'X' characters. The X string will be modified to form the
+ * name of a file that didn't exist. This operation never fails, but the
+ * returned object might not support any I/O operation if @tmpl is malformed.
+ *
+ * Returns: (transfer full): a new #GFile.
+ *  Free the returned object with g_object_unref().
+ **/
+GFile *
+g_file_new_for_temp (const char *tmpl)
+{
+  gint fd;
+  gchar *path;
+  GFile *file;
+  GError *error = NULL;
+
+  g_return_val_if_fail (tmpl != NULL, NULL);
+
+  fd = g_file_open_tmp (tmpl, &path, &error);
+
+  if (fd != -1) {
+    close (fd);
+    g_unlink (path);
+    file = g_file_new_for_path (path);
+    g_free (path);
+    return file;
+  }
+  else {
+    g_warning ("Could not create temporary file: %s", error->message);
+    g_error_free (error);
+    return NULL;
+  }
+}
+
+/**
  * g_file_mount_enclosing_volume:
  * @location: input #GFile.
  * @flags: flags affecting the operation
diff --git a/gio/gfile.h b/gio/gfile.h
index 500d7de..c9d7347 100644
--- a/gio/gfile.h
+++ b/gio/gfile.h
@@ -550,6 +550,7 @@ GType                   g_file_get_type                   (void) G_GNUC_CONST;
 GFile *                 g_file_new_for_path               (const char                 *path);
 GFile *                 g_file_new_for_uri                (const char                 *uri);
 GFile *                 g_file_new_for_commandline_arg    (const char                 *arg);
+GFile *                 g_file_new_for_temp               (const char                 *tmpl);
 GFile *                 g_file_parse_name                 (const char                 *parse_name);
 GFile *                 g_file_dup                        (GFile                      *file);
 guint                   g_file_hash                       (gconstpointer               file);
diff --git a/gio/tests/file.c b/gio/tests/file.c
index c7734a9..27b5c4b 100644
--- a/gio/tests/file.c
+++ b/gio/tests/file.c
@@ -102,7 +102,6 @@ typedef struct
   gint monitor_created;
   gint monitor_deleted;
   gint monitor_changed;
-  gchar *monitor_path;
   gint pos;
   gchar *data;
   gchar *buffer;
@@ -118,8 +117,6 @@ monitor_changed (GFileMonitor      *monitor,
 {
   CreateDeleteData *data = user_data;
 
-  g_assert_cmpstr (data->monitor_path, ==, g_file_get_path (file));
-
   if (event_type == G_FILE_MONITOR_EVENT_CREATED)
     data->monitor_created++;
   if (event_type == G_FILE_MONITOR_EVENT_DELETED)
@@ -394,7 +391,6 @@ test_create_delete (gconstpointer d)
 {
   GError *error;
   CreateDeleteData *data;
-  int tmpfd;
 
   data = g_new0 (CreateDeleteData, 1);
 
@@ -402,14 +398,7 @@ test_create_delete (gconstpointer d)
   data->data = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789";
   data->pos = 0;
 
-  /* Using tempnam() would be easier here, but causes a compile warning */
-  tmpfd = g_file_open_tmp ("g_file_create_delete_XXXXXX",
-			   &data->monitor_path, NULL);
-  g_assert_cmpint (tmpfd, !=, -1);
-  close (tmpfd);
-  remove (data->monitor_path);
-
-  data->file = g_file_new_for_path (data->monitor_path);
+  data->file = g_file_new_for_temp ("g_file_create_delete_XXXXXX");
   g_assert (!g_file_query_exists  (data->file, NULL));
 
   error = NULL;
@@ -440,7 +429,6 @@ test_create_delete (gconstpointer d)
   g_object_unref (data->ostream);
   g_object_unref (data->istream);
   g_object_unref (data->file);
-  free (data->monitor_path);
   g_free (data->buffer);
   g_free (data);
 }
@@ -523,8 +511,6 @@ static void
 test_replace_load (void)
 {
   ReplaceLoadData *data;
-  gchar *path;
-  int tmpfd;
 
   data = g_new0 (ReplaceLoadData, 1);
   data->again = TRUE;
@@ -557,14 +543,7 @@ test_replace_load (void)
     " * make a backup of @file.\n"
     " **/\n";
 
-  /* Using tempnam() would be easier here, but causes a compile warning */
-  tmpfd = g_file_open_tmp ("g_file_replace_load_XXXXXX",
-			   &path, NULL);
-  g_assert_cmpint (tmpfd, !=, -1);
-  close (tmpfd);
-  remove (path);
-
-  data->file = g_file_new_for_path (path);
+  data->file = g_file_new_for_temp ("g_file_replace_load_XXXXXX");
   g_assert (!g_file_query_exists (data->file, NULL));
 
   data->loop = g_main_loop_new (NULL, FALSE);
@@ -583,8 +562,6 @@ test_replace_load (void)
 
   g_main_loop_unref (data->loop);
   g_object_unref (data->file);
-  g_free (data);
-  free (path);
 }
 
 int
