[librsvg] Use g_file_get_contents to local load image data.



commit 70d9f65868eb9dfd923fa26f8a3fc326c816db9c
Author: Hiroyuki Ikezoe <hiikezoe gnome org>
Date:   Thu May 27 20:27:32 2010 +0900

    Use g_file_get_contents to local load image data.

 rsvg-image.c |   35 ++++++-----------------------------
 1 files changed, 6 insertions(+), 29 deletions(-)
---
diff --git a/rsvg-image.c b/rsvg-image.c
index 9c8627a..77494b6 100644
--- a/rsvg-image.c
+++ b/rsvg-image.c
@@ -93,10 +93,8 @@ rsvg_acquire_file_resource (const char *filename, const char *base_uri, GError *
 {
     GByteArray *array;
     gchar *path;
-
-    guchar buffer[4096];
-    int length;
-    FILE *f;
+    gchar *data = NULL;
+    gsize length;
 
     rsvg_return_val_if_fail (filename != NULL, NULL, error);
 
@@ -104,36 +102,15 @@ rsvg_acquire_file_resource (const char *filename, const char *base_uri, GError *
     if (path == NULL)
         return NULL;
 
-    f = fopen (path, "rb");
-    g_free (path);
-
-    if (!f) {
-        g_set_error (error,
-                     G_FILE_ERROR,
-                     g_file_error_from_errno (errno),
-                     _("Failed to open file '%s': %s"), filename, g_strerror (errno));
+    if (!g_file_get_contents (path, &data, &length, error)) {
+        g_free (path);
         return NULL;
     }
 
-    /* TODO: an optimization is to use the file's size */
     array = g_byte_array_new ();
 
-    while (!feof (f)) {
-        length = fread (buffer, 1, sizeof (buffer), f);
-        if (length > 0) {
-            if (g_byte_array_append (array, buffer, length) == NULL) {
-                fclose (f);
-                g_byte_array_free (array, TRUE);
-                return NULL;
-            }
-        } else if (ferror (f)) {
-            fclose (f);
-            g_byte_array_free (array, TRUE);
-            return NULL;
-        }
-    }
-
-    fclose (f);
+    g_byte_array_append (array, (guint8 *)data, length);
+    g_free (data);
 
     return array;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]