#include "gappinfo.h"
#include "gfileinputstream.h"
#include "gfileoutputstream.h"
+#include "glocalfileoutputstream.h"
+#include "glocalfileiostream.h"
#include "gcancellable.h"
#include "gasyncresult.h"
#include "gioerror.h"
* 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_tmp() to create a temporary file from a template.
* 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
* @source: input #GFile.
* @destination: destination #GFile
* @flags: set of #GFileCopyFlags
- * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
- * @progress_callback: (scope call): function to callback with progress information
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
+ * @progress_callback: (allow-none) (scope call): function to callback with
+ * progress information, or %NULL if progress information is not needed
* @progress_callback_data: (closure): user data to pass to @progress_callback
* @error: #GError to set on error, or %NULL
*
*
* If @cancellable is not %NULL, then the operation can be cancelled by
* triggering the cancellable object from another thread. If the operation
- * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
- *
+ * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
+ *
* If @progress_callback is not %NULL, then the operation can be monitored by
* setting this to a #GFileProgressCallback function. @progress_callback_data
* will be passed to this function. It is guaranteed that this callback will
* be called after all data has been transferred with the total number of bytes
* copied during the operation.
- *
+ *
* If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
* error is returned, independent on the status of the @destination.
*
* error is returned. If trying to overwrite a directory with a directory the
* G_IO_ERROR_WOULD_MERGE error is returned.
*
- * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
- * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
- * is returned.
+ * If the source is a directory and the target does not exist, or
+ * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then the
+ * G_IO_ERROR_WOULD_RECURSE error is returned.
*
* If you are interested in copying the #GFile object itself (not the on-disk
* file), see g_file_dup().
* @source: input #GFile.
* @destination: destination #GFile
* @flags: set of #GFileCopyFlags
- * @io_priority: the <link linkend="io-priority">I/O priority</link>
- * of the request.
- * @cancellable: optional #GCancellable object, %NULL to ignore.
- * @progress_callback: function to callback with progress information
- * @progress_callback_data: user data to pass to @progress_callback
+ * @io_priority: the <link linkend="io-priority">I/O priority</link>
+ * of the request
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
+ * @progress_callback: (allow-none): function to callback with progress
+ * information, or %NULL if progress information is not needed
+ * @progress_callback_data: (closure): user data to pass to @progress_callback
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
* @user_data: the data to pass to callback function
*
- * Copies the file @source to the location specified by @destination
+ * Copies the file @source to the location specified by @destination
* asynchronously. For details of the behaviour, see g_file_copy().
*
* If @progress_callback is not %NULL, then that function that will be called
* @file: input #GFile.
* @attribute: a string containing the attribute's name.
* @type: The type of the attribute
- * @value_p: a pointer to the value (or the pointer itself if the type is a pointer type)
+ * @value_p: (allow-none): a pointer to the value (or the pointer itself if the type is a pointer type)
* @flags: a set of #GFileQueryInfoFlags.
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
* @error: a #GError, or %NULL
* Sets an attribute in the file with attribute name @attribute to @value.
*
* Some attributes can be unset by setting @attribute to
- * %G_FILE_ATTRIBUTE_TYPE_INVALID and @value to %NULL.
+ * %G_FILE_ATTRIBUTE_TYPE_INVALID and @value_p to %NULL.
*
* If @cancellable is not %NULL, then the operation can be cancelled by
* triggering the cancellable object from another thread. If the operation
return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
}
-
+
+/**
+ * g_file_new_tmp:
+ * @tmpl: (type filename) (allow-none): Template for the file
+ * name, as in g_file_open_tmp(), or %NULL for a default template.
+ * @iostream: (out): on return, a #GFileIOStream for the created file.
+ * @error: a #GError, or %NULL
+ *
+ * Opens a file in the preferred directory for temporary files (as
+ * returned by g_get_tmp_dir()) and returns a #GFile and
+ * #GFileIOStream pointing to it.
+ *
+ * @template should be a string in the GLib file name encoding
+ * containing a sequence of six 'X' characters, and containing no
+ * directory components. If it is %NULL, a default template is used.
+ *
+ * Unlike the other #GFile constructors, this will return %NULL if
+ * a temporary file could not be created.
+ *
+ * Returns: (transfer full): a new #GFile.
+ * Free the returned object with g_object_unref().
+ **/
+GFile *
+g_file_new_tmp (const char *tmpl,
+ GFileIOStream **iostream,
+ GError **error)
+{
+ gint fd;
+ gchar *path;
+ GFile *file;
+ GFileOutputStream *output;
+
+ g_return_val_if_fail (tmpl != NULL, NULL);
+ g_return_val_if_fail (iostream != NULL, NULL);
+
+ fd = g_file_open_tmp (tmpl, &path, error);
+ if (fd == -1)
+ return NULL;
+
+ file = g_file_new_for_path (path);
+
+ output = _g_local_file_output_stream_new (fd);
+ *iostream = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
+
+ g_object_unref (output);
+ g_free (path);
+
+ return file;
+}
+
/**
* g_file_parse_name:
* @parse_name: a file name or path to be parsed.