mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
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
This commit is contained in:
parent
c7f2a7e431
commit
1cce5dda18
20
gio/gfile.c
20
gio/gfile.c
@ -2777,9 +2777,10 @@ copy_stream_with_progress (GInputStream *in,
|
|||||||
gpointer progress_callback_data,
|
gpointer progress_callback_data,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gssize n_read, n_written;
|
gssize n_read;
|
||||||
|
gsize n_written;
|
||||||
goffset current_size;
|
goffset current_size;
|
||||||
char *buffer, *p;
|
char *buffer;
|
||||||
gboolean res;
|
gboolean res;
|
||||||
goffset total_size;
|
goffset total_size;
|
||||||
GFileInfo *info;
|
GFileInfo *info;
|
||||||
@ -2833,20 +2834,7 @@ copy_stream_with_progress (GInputStream *in,
|
|||||||
|
|
||||||
current_size += n_read;
|
current_size += n_read;
|
||||||
|
|
||||||
p = buffer;
|
res = g_output_stream_write_all (out, buffer, n_read, &n_written, cancellable, error);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user