[glib] gio-tool-save: Use g_output_stream_write_all instead of while



commit 78fa67e70c600633025d81fce4689b778540064d
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Aug 11 13:47:14 2017 +0200

    gio-tool-save: Use g_output_stream_write_all instead of while
    
    Simplify the read-write copy code and use g_output_stream_write_all
    instead of while and g_output_stream_write.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786462

 gio/gio-tool-save.c |   26 ++++++++------------------
 1 files changed, 8 insertions(+), 18 deletions(-)
---
diff --git a/gio/gio-tool-save.c b/gio/gio-tool-save.c
index e6b131f..700685d 100644
--- a/gio/gio-tool-save.c
+++ b/gio/gio-tool-save.c
@@ -67,7 +67,6 @@ save (GFile *file)
   GOutputStream *out;
   GFileCreateFlags flags;
   char *buffer;
-  char *p;
   gssize res;
   gboolean close_res;
   GError *error;
@@ -99,23 +98,14 @@ save (GFile *file)
       res = read (STDIN_FILENO, buffer, STREAM_BUFFER_SIZE);
       if (res > 0)
        {
-         gssize written;
-
-         p = buffer;
-         while (res > 0)
-           {
-             error = NULL;
-             written = g_output_stream_write (out, p, res, NULL, &error);
-             if (written == -1)
-               {
-                 save_res = FALSE;
-                  print_error ("%s", error->message);
-                  g_clear_error (error);
-                 goto out;
-               }
-             res -= written;
-             p += written;
-           }
+          g_output_stream_write_all (out, buffer, res, NULL, NULL, &error);
+          if (error != NULL)
+            {
+              save_res = FALSE;
+              print_error ("%", error->message);
+              g_clear_error (&error);
+              goto out;
+            }
        }
       else if (res < 0)
        {


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