[glib] gfile: Use g_output_stream_write_all instead of while



commit 1cce5dda1837e5feba10f96ef6a9422ead6336c6
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Aug 11 13:43:35 2017 +0200

    gfile: 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/gfile.c |   20 ++++----------------
 1 files changed, 4 insertions(+), 16 deletions(-)
---
diff --git a/gio/gfile.c b/gio/gfile.c
index 9967b73..8a78e95 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -2777,9 +2777,10 @@ copy_stream_with_progress (GInputStream           *in,
                            gpointer                progress_callback_data,
                            GError                **error)
 {
-  gssize n_read, n_written;
+  gssize n_read;
+  gsize n_written;
   goffset current_size;
-  char *buffer, *p;
+  char *buffer;
   gboolean res;
   goffset total_size;
   GFileInfo *info;
@@ -2833,20 +2834,7 @@ copy_stream_with_progress (GInputStream           *in,
 
       current_size += n_read;
 
-      p = buffer;
-      while (n_read > 0)
-        {
-          n_written = g_output_stream_write (out, p, n_read, cancellable, error);
-          if (n_written == -1)
-            {
-              res = FALSE;
-              break;
-            }
-
-          p += n_written;
-          n_read -= n_written;
-        }
-
+      res = g_output_stream_write_all (out, buffer, n_read, &n_written, cancellable, error);
       if (!res)
         break;
 


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