[gimp/gimp-2-10] app: add gimp_data_input_stream_read_line_always()



commit d544e5d7b2a50c65925c8135c8e87f2581a923e4
Author: Ell <ell_se yahoo com>
Date:   Wed Jun 20 14:24:43 2018 -0400

    app: add gimp_data_input_stream_read_line_always()
    
    ... which is a drop-in replacement for
    g_data_input_stream_read_line(), however, it always returns a non-
    NULL value when there's no error.  If the end-of-file is reached,
    an empty string is returned.
    
    (cherry picked from commit e090b910c07e31080ff349aa6951c4173f44e122)

 app/core/gimp-utils.c | 29 +++++++++++++++++++++++++++++
 app/core/gimp-utils.h |  5 +++++
 2 files changed, 34 insertions(+)
---
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index 321e522ea3..825fc50ec1 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -815,6 +815,35 @@ gimp_file_with_new_extension (GFile *file,
   return ret;
 }
 
+gchar *
+gimp_data_input_stream_read_line_always (GDataInputStream  *stream,
+                                         gsize             *length,
+                                         GCancellable      *cancellable,
+                                         GError           **error)
+{
+  GError *temp_error = NULL;
+  gchar  *result;
+
+  g_return_val_if_fail (G_IS_DATA_INPUT_STREAM (stream), NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+  if (! error)
+    error = &temp_error;
+
+  result = g_data_input_stream_read_line (stream, length, cancellable, error);
+
+  if (! result && ! *error)
+    {
+      result = g_strdup ("");
+
+      if (length) *length = 0;
+    }
+
+  g_clear_error (&temp_error);
+
+  return result;
+}
+
 
 /*  debug stuff  */
 
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index 2e9e275c38..64847bd957 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -83,6 +83,11 @@ gchar      * gimp_file_get_extension               (GFile           *file);
 GFile      * gimp_file_with_new_extension          (GFile           *file,
                                                     GFile           *ext_file);
 
+gchar      * gimp_data_input_stream_read_line_always (GDataInputStream  *stream,
+                                                      gsize             *length,
+                                                      GCancellable      *cancellable,
+                                                      GError           **error);
+
 GimpImage  * gimp_create_image_from_buffer         (Gimp            *gimp,
                                                     GeglBuffer      *buffer,
                                                     const gchar     *image_name);


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