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
This commit is contained in:
Ondrej Holy 2017-08-11 13:47:14 +02:00
parent 1cce5dda18
commit 78fa67e70c

View File

@ -67,7 +67,6 @@ save (GFile *file)
GOutputStream *out; GOutputStream *out;
GFileCreateFlags flags; GFileCreateFlags flags;
char *buffer; char *buffer;
char *p;
gssize res; gssize res;
gboolean close_res; gboolean close_res;
GError *error; GError *error;
@ -99,23 +98,14 @@ save (GFile *file)
res = read (STDIN_FILENO, buffer, STREAM_BUFFER_SIZE); res = read (STDIN_FILENO, buffer, STREAM_BUFFER_SIZE);
if (res > 0) if (res > 0)
{ {
gssize written; g_output_stream_write_all (out, buffer, res, NULL, NULL, &error);
if (error != NULL)
p = buffer; {
while (res > 0) save_res = FALSE;
{ print_error ("%", error->message);
error = NULL; g_clear_error (&error);
written = g_output_stream_write (out, p, res, NULL, &error); goto out;
if (written == -1) }
{
save_res = FALSE;
print_error ("%s", error->message);
g_clear_error (error);
goto out;
}
res -= written;
p += written;
}
} }
else if (res < 0) else if (res < 0)
{ {