mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 15:06:14 +01:00
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:
parent
1cce5dda18
commit
78fa67e70c
@ -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)
|
||||
g_output_stream_write_all (out, buffer, res, NULL, NULL, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
save_res = FALSE;
|
||||
print_error ("%s", error->message);
|
||||
g_clear_error (error);
|
||||
print_error ("%", error->message);
|
||||
g_clear_error (&error);
|
||||
goto out;
|
||||
}
|
||||
res -= written;
|
||||
p += written;
|
||||
}
|
||||
}
|
||||
else if (res < 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user