diff --git a/gio/gfile.c b/gio/gfile.c
index 86111d2..2b2f6c2 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -5890,6 +5890,34 @@ g_file_new_for_uri (const char *uri)
   return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
 }
   
+GFile *
+g_file_new_temp (const char     *template,
+                 GFileIOStream **iostream)
+{
+  GFileIface *iface;
+  gint fd;
+  gchar *path;
+  GFile *file;
+  GError *error = NULL;
+
+  g_return_val_if_fail (template != NULL, NULL);
+
+  fd = g_file_open_tmp (template, &path, &error);
+
+  if (fd != -1) {
+    file = g_file_new_for_path (path);
+    iface = G_FILE_GET_IFACE (file);
+    *iostream = iface->open_readwrite_for_fd (fd, &error);
+    g_free (path);
+    return file;
+  }
+  else {
+    g_warning ("Could not create temporary file: %s", error->message);
+    g_error_free (error);
+    return NULL;
+  }
+}
+
 /**
  * g_file_parse_name:
  * @parse_name: a file name or path to be parsed.
diff --git a/gio/gfile.h b/gio/gfile.h
index 500d7de..4365e68 100644
--- a/gio/gfile.h
+++ b/gio/gfile.h
@@ -463,6 +463,8 @@ struct _GFileIface
   GFileIOStream *     (* open_readwrite_finish)       (GFile                *file,
                                                        GAsyncResult         *res,
                                                        GError              **error);
+  GFileIOStream *     (* open_readwrite_for_fd)       (int                   fd,
+                                                       GError              **error);
   GFileIOStream *     (* create_readwrite)            (GFile                *file,
 						       GFileCreateFlags      flags,
                                                        GCancellable         *cancellable,
@@ -550,6 +552,8 @@ 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_temp                   (const char                 *template,
+                                                           GFileIOStream             **iostream);
 GFile *                 g_file_parse_name                 (const char                 *parse_name);
 GFile *                 g_file_dup                        (GFile                      *file);
 guint                   g_file_hash                       (gconstpointer               file);
@@ -642,6 +646,8 @@ void                    g_file_open_readwrite_async       (GFile
 GFileIOStream *         g_file_open_readwrite_finish      (GFile                      *file,
 							   GAsyncResult               *res,
 							   GError                    **error);
+GFileIOStream *         g_file_open_readwrite_for_fd      (int                         fd,
+                                                           GError                    **error);
 GFileIOStream *         g_file_create_readwrite           (GFile                      *file,
 							   GFileCreateFlags            flags,
 							   GCancellable               *cancellable,
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index 287ceb7..416156d 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -1375,6 +1375,20 @@ g_local_file_open_readwrite (GFile                      *file,
 }
 
 static GFileIOStream *
+g_local_file_open_readwrite_for_fd (int                    fd,
+                                    GError               **error)
+{
+  GFileOutputStream *output;
+  GFileIOStream *res;
+
+  output = _g_local_file_output_stream_new (fd);
+
+  res = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
+  g_object_unref (output);
+  return res;
+}
+
+static GFileIOStream *
 g_local_file_create_readwrite (GFile                      *file,
 			       GFileCreateFlags            flags,
 			       GCancellable               *cancellable,
@@ -2388,6 +2402,7 @@ g_local_file_file_iface_init (GFileIface *iface)
   iface->create = g_local_file_create;
   iface->replace = g_local_file_replace;
   iface->open_readwrite = g_local_file_open_readwrite;
+  iface->open_readwrite_for_fd = g_local_file_open_readwrite_for_fd;
   iface->create_readwrite = g_local_file_create_readwrite;
   iface->replace_readwrite = g_local_file_replace_readwrite;
   iface->delete_file = g_local_file_delete;
diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c
index aff270c..a310fcd 100644
--- a/gio/glocalfileoutputstream.c
+++ b/gio/glocalfileoutputstream.c
@@ -541,6 +541,16 @@ g_local_file_output_stream_query_info (GFileOutputStream  *stream,
 }
 
 GFileOutputStream *
+_g_local_file_output_stream_new (int fd)
+{
+  GLocalFileOutputStream *stream;
+
+  stream = g_object_new (G_TYPE_LOCAL_FILE_OUTPUT_STREAM, NULL);
+  stream->priv->fd = fd;
+  return G_FILE_OUTPUT_STREAM (stream);
+}
+
+GFileOutputStream *
 _g_local_file_output_stream_open  (const char        *filename,
 				   gboolean          readable,
 				   GCancellable      *cancellable,
diff --git a/gio/glocalfileoutputstream.h b/gio/glocalfileoutputstream.h
index 831c37f..844eacb 100644
--- a/gio/glocalfileoutputstream.h
+++ b/gio/glocalfileoutputstream.h
@@ -59,6 +59,7 @@ gboolean _g_local_file_output_stream_really_close (GLocalFileOutputStream *out,
 						   GCancellable   *cancellable,
 						   GError        **error);
 
+GFileOutputStream * _g_local_file_output_stream_new      (int               fd);
 GFileOutputStream * _g_local_file_output_stream_open     (const char       *filename,
 							  gboolean          readable,
                                                           GCancellable     *cancellable,
