From 1cce5dda1837e5feba10f96ef6a9422ead6336c6 Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Fri, 11 Aug 2017 13:43:35 +0200 Subject: [PATCH] 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 file changed, 4 insertions(+), 16 deletions(-) diff --git a/gio/gfile.c b/gio/gfile.c index 9967b7360..8a78e95c9 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;