[gegl] gegl-gio: Add a helper for opening output stream
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] gegl-gio: Add a helper for opening output stream
- Date: Wed, 30 Sep 2015 14:20:43 +0000 (UTC)
commit af4368284e35ad134cde80e762f05e651a746edb
Author: Martin Blanchard <tchaik gmx com>
Date: Sat Sep 26 12:32:50 2015 +0200
gegl-gio: Add a helper for opening output stream
Similarly to what gegl_gio_open_input_stream() does for input streams,
this adds a gegl_gio_open_ouput_stream(), allowing one to open an
output stream from a URI or path.
https://bugzilla.gnome.org/show_bug.cgi?id=752037
gegl/gegl-gio-private.h | 3 ++
gegl/gegl-gio.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 55 insertions(+), 1 deletions(-)
---
diff --git a/gegl/gegl-gio-private.h b/gegl/gegl-gio-private.h
index 354f545..8d2b32b 100644
--- a/gegl/gegl-gio-private.h
+++ b/gegl/gegl-gio-private.h
@@ -27,6 +27,9 @@ G_BEGIN_DECLS
GInputStream *
gegl_gio_open_input_stream(const gchar *uri, const gchar *path, GFile **out_file, GError **err);
+GOutputStream *
+gegl_gio_open_output_stream(const gchar *uri, const gchar *path, GFile **out_file, GError **err);
+
gboolean
gegl_gio_uri_is_datauri(const gchar *uri);
diff --git a/gegl/gegl-gio.c b/gegl/gegl-gio.c
index 39b3d72..b6cbe13 100644
--- a/gegl/gegl-gio.c
+++ b/gegl/gegl-gio.c
@@ -22,9 +22,11 @@
#ifdef G_OS_WIN32
#include <windows.h>
-#include <gio/gwin32inputstream.h>
+#include <gio/gwin32inputstream.h>
+#include <gio/gwin32outputstream.h>
#else
#include <gio/gunixinputstream.h>
+#include <gio/gunixoutputstream.h>
#endif
/**
@@ -165,3 +167,52 @@ gegl_gio_open_input_stream(const gchar *uri, const gchar *path, GFile **out_file
return fis;
}
+
+/**
+ * gegl_gio_open_output_stream:
+ * @uri: (allow none) URI to open. @uri is preferred over @path if both are set.
+ * @path: (allow none) path to open.
+ * @out_file: (out) (transfer full): return location for GFile, if stream is for a file.
+ *
+ * Return value: (transfer full): A new #GOutputStream, free with g_object_unref().
+ *
+ * Note: currently private API.
+ */
+GOutputStream *
+gegl_gio_open_output_stream(const gchar *uri, const gchar *path, GFile **out_file, GError **err)
+{
+ GOutputStream *stream = NULL;
+ const gboolean close = FALSE;
+ GFile *file = NULL;
+
+ g_return_val_if_fail(uri || path, NULL);
+ g_return_val_if_fail(out_file, NULL);
+
+ if (path && g_strcmp0(path, "-") == 0)
+ {
+#ifdef G_OS_WIN32
+ stream = g_win32_output_stream_new(GetStdHandle(STD_OUTPUT_HANDLE), close);
+#else
+ stream = g_unix_output_stream_new(STDOUT_FILENO, close);
+#endif
+ }
+ else if (uri && strlen(uri) > 0)
+ file = g_file_new_for_uri(uri);
+ else if (path && strlen(path) > 0)
+ file = g_file_new_for_path(path);
+ else
+ return NULL;
+
+ if (file != NULL)
+ {
+ g_assert(stream == NULL);
+
+ stream = G_OUTPUT_STREAM(g_file_replace(file, NULL,
+ FALSE, G_FILE_CREATE_NONE,
+ NULL, err));
+
+ *out_file = file;
+ }
+
+ return stream;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]