[gimp] libgimpbase: add gimp_output_stream_[v]printf()



commit 99937ddfceb13e355c9d65155921c38d107cd735
Author: Michael Natterer <mitch gimp org>
Date:   Thu Nov 28 00:29:43 2013 +0100

    libgimpbase: add gimp_output_stream_[v]printf()
    
    Temporary, to be removed when we depend on glib 2.40, which will
    clearly be before gimp 2.10

 libgimpbase/gimpbase.def |    2 ++
 libgimpbase/gimputils.c  |   46 +++++++++++++++++++++++++++++++++++++++++++++-
 libgimpbase/gimputils.h  |   15 +++++++++++++++
 3 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index d2bfa5a..5f925a4 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -65,6 +65,8 @@ EXPORTS
        gimp_metadata_set_resolution
        gimp_micro_version
        gimp_minor_version
+       gimp_output_stream_printf
+       gimp_output_stream_vprintf
        gimp_paint_application_mode_get_type
        gimp_param_memsize_get_type
        gimp_param_parasite_get_type
diff --git a/libgimpbase/gimputils.c b/libgimpbase/gimputils.c
index 5ddec3a..0520632 100644
--- a/libgimpbase/gimputils.c
+++ b/libgimpbase/gimputils.c
@@ -24,7 +24,7 @@
 #include <string.h>
 #include <stdio.h>
 
-#include <glib-object.h>
+#include <gio/gio.h>
 
 #include "gimpbasetypes.h"
 #include "gimputils.h"
@@ -732,3 +732,47 @@ gimp_flags_value_get_help (GFlagsClass *flags_class,
 
   return NULL;
 }
+
+gboolean
+gimp_output_stream_printf (GOutputStream  *stream,
+                           gsize          *bytes_written,
+                           GCancellable   *cancellable,
+                           GError        **error,
+                           const gchar    *format,
+                           ...)
+{
+  va_list  args;
+  gboolean success;
+
+  va_start (args, format);
+  success = gimp_output_stream_vprintf (stream, bytes_written, cancellable,
+                                        error, format, args);
+  va_end (args);
+
+  return success;
+}
+
+gboolean
+gimp_output_stream_vprintf (GOutputStream  *stream,
+                            gsize          *bytes_written,
+                            GCancellable   *cancellable,
+                            GError        **error,
+                            const gchar    *format,
+                            va_list         args)
+{
+  gchar    *text;
+  gboolean  success;
+
+  g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
+  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (stream), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+  g_return_val_if_fail (format != NULL, FALSE);
+
+  text = g_strdup_vprintf (format, args);
+  success = g_output_stream_write_all (stream,
+                                       text, strlen (text),
+                                       bytes_written, cancellable, error);
+  g_free (text);
+
+  return success;
+}
diff --git a/libgimpbase/gimputils.h b/libgimpbase/gimputils.h
index 06e8add..533ba59 100644
--- a/libgimpbase/gimputils.h
+++ b/libgimpbase/gimputils.h
@@ -65,6 +65,21 @@ const gchar   * gimp_flags_value_get_desc    (GFlagsClass  *flags_class,
 const gchar   * gimp_flags_value_get_help    (GFlagsClass  *flags_class,
                                               GFlagsValue  *flags_value);
 
+/* temporary, to be removed when we depend on glib 2.40, which will
+ * clearly be before gimp 2.10
+ */
+gboolean        gimp_output_stream_printf    (GOutputStream  *stream,
+                                              gsize          *bytes_written,
+                                              GCancellable   *cancellable,
+                                              GError        **error,
+                                              const gchar    *format,
+                                              ...) G_GNUC_PRINTF (5, 6);
+gboolean        gimp_output_stream_vprintf   (GOutputStream  *stream,
+                                              gsize          *bytes_written,
+                                              GCancellable   *cancellable,
+                                              GError        **error,
+                                              const gchar    *format,
+                                              va_list         args) G_GNUC_PRINTF (5, 0);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]