diff options
author | Colin Walters <walters@verbum.org> | 2013-01-25 12:05:26 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-01-29 09:46:04 -0500 |
commit | f398bec5bcc0d924e2401c76a6b94133e9490835 (patch) | |
tree | d740e8bdc7cd2dadb92e16219cdebc2ed8fad974 /gio/gfile.c | |
parent | cf68300d27784ab5baaf6ef4761cead0ec404b1f (diff) | |
download | glib-f398bec5bcc0d924e2401c76a6b94133e9490835.tar.gz glib-f398bec5bcc0d924e2401c76a6b94133e9490835.tar.bz2 glib-f398bec5bcc0d924e2401c76a6b94133e9490835.zip |
Add g_close(), use it
There are two benefits to this:
1) We can centralize any operating system specific knowledge of
close-vs-EINTR handling. For example, while on Linux we should never
retry, if someone cared enough later about HP-UX, they could come by
and change this one spot.
2) For places that do care about the return value and want to provide
the caller with a GError, this function makes it convenient to do so.
Note that gspawn.c had an incorrect EINTR loop-retry around close().
https://bugzilla.gnome.org/show_bug.cgi?id=682819
Diffstat (limited to 'gio/gfile.c')
-rw-r--r-- | gio/gfile.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/gio/gfile.c b/gio/gfile.c index 3d78d7205..04b5239e5 100644 --- a/gio/gfile.c +++ b/gio/gfile.c @@ -46,6 +46,7 @@ #endif #include "gfile.h" +#include "glib/gstdio.h" #ifdef G_OS_UNIX #include "glib-unix.h" #endif @@ -2843,7 +2844,7 @@ splice_stream_with_progress (GInputStream *in, gpointer progress_callback_data, GError **error) { - int buffer[2]; + int buffer[2] = { -1, -1 }; gboolean res; goffset total_size; loff_t offset_in; @@ -2907,9 +2908,17 @@ splice_stream_with_progress (GInputStream *in, if (progress_callback) progress_callback (offset_in, total_size, progress_callback_data); + if (!g_close (buffer[0], error)) + goto out; + buffer[0] = -1; + if (!g_close (buffer[1], error)) + goto out; + buffer[1] = -1; out: - close (buffer[0]); - close (buffer[1]); + if (buffer[0] != -1) + (void) g_close (buffer[0], NULL); + if (buffer[1] != -1) + (void) g_close (buffer[1], NULL); return res; } |