[libgsf] gsf-gio: cleanups.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgsf] gsf-gio: cleanups.
- Date: Tue, 8 Nov 2011 20:11:49 +0000 (UTC)
commit 6243561d53d021b0b7f1568eb39c46f62aad2c49
Author: Morten Welinder <terra gnome org>
Date: Tue Nov 8 15:11:33 2011 -0500
gsf-gio: cleanups.
ChangeLog | 6 ++++++
gsf/gsf-input-gio.c | 47 ++++++++++++++++++++++++++++++-----------------
2 files changed, 36 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7180a5e..df9143b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-11-08 Morten Welinder <terra gnome org>
+
+ * gsf/gsf-input-gio.c (gsf_input_gio_read): Handle unexpected EOF
+ from source. Never request more than gio is documented to handle.
+ (make_local_copy): Set name from file.
+
2011-09-08 Morten Welinder <terra gnome org>
* configure.in: Switch to AM_MAINTAINER_MODE([enable]).
diff --git a/gsf/gsf-input-gio.c b/gsf/gsf-input-gio.c
index f13f991..ef949fd 100644
--- a/gsf/gsf-input-gio.c
+++ b/gsf/gsf-input-gio.c
@@ -48,6 +48,17 @@ can_seek (GInputStream *stream)
return g_seekable_can_seek (G_SEEKABLE (stream));
}
+static void
+set_name_from_file (GsfInput *input, GFile *file)
+{
+ GFileInfo *info = g_file_query_info
+ (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL);
+ if (info) {
+ gsf_input_set_name (input, g_file_info_get_name (info));
+ g_object_unref (info);
+ }
+}
+
static GsfInput *
make_local_copy (GFile *file, GInputStream *stream)
{
@@ -96,6 +107,9 @@ make_local_copy (GFile *file, GInputStream *stream)
g_input_stream_close (stream, NULL, NULL);
g_object_unref (stream);
+
+ set_name_from_file (copy, file);
+
return copy;
}
@@ -143,12 +157,7 @@ gsf_input_gio_new (GFile *file, GError **err)
input->buf = NULL;
input->buf_size = 0;
- info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL);
- if (info) {
- gsf_input_set_name (GSF_INPUT (input), g_file_info_get_name (info));
- g_object_unref (info);
- }
-
+ set_name_from_file (GSF_INPUT (input), file);
return GSF_INPUT (input);
}
@@ -263,21 +272,25 @@ gsf_input_gio_read (GsfInput *input, size_t num_bytes, guint8 *buffer)
buffer = gio->buf;
}
- while (1) {
- gssize nread;
-
- nread = g_input_stream_read (gio->stream, (buffer + total_read), (num_bytes - total_read), NULL, NULL);
+ while (total_read < num_bytes) {
+ gssize try_to_read = MIN (G_MAXSSIZE, num_bytes - total_read);
+ gssize nread = g_input_stream_read (gio->stream,
+ buffer + total_read,
+ try_to_read,
+ NULL, NULL);
- if (nread >= 0) {
+ if (nread > 0) {
total_read += nread;
- if ((size_t) total_read == num_bytes) {
- return buffer;
- }
- } else
- break;
+ } else {
+ /*
+ * Getting zero means EOF which ins't supposed to
+ * happen. Negative means error.
+ */
+ return NULL;
+ }
}
- return NULL;
+ return buffer;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]