Permalink
Browse files

asx, pls: Load files even if vfs_fsize() fails.

  • Loading branch information...
1 parent ba714e4 commit 47dcc58af9835489cff769d30d3cd9e4aadc08a8 @jlindgren90 jlindgren90 committed Mar 10, 2012
Showing with 48 additions and 6 deletions.
  1. +24 −3 src/asx/util.c
  2. +24 −3 src/pls/util.c
View
@@ -67,12 +67,33 @@ INIFile * open_ini_file (VFSFile * file)
gpointer section_hash, key_hash;
gsize off = 0;
+ gchar * buffer = NULL;
gint64 filesize = vfs_fsize (file);
+
+ if (filesize > 0)
+ {
+ buffer = g_malloc (filesize);
+ filesize = vfs_fread (buffer, 1, filesize, file);
+ }
+ else
+ {
+ gint64 readed;
+ filesize = 0;
+
+ do
+ {
+ buffer = g_realloc (buffer, filesize + 4096);
+ readed = vfs_fread (buffer + filesize, 1, 4096, file);
+ filesize += readed;
+ }
+ while (readed > 0);
+ }
+
if (filesize < 1)
+ {
+ g_free (buffer);
return NULL;
-
- gchar * buffer = g_malloc (filesize);
- filesize = vfs_fread (buffer, 1, filesize, file);
+ }
section_name = g_string_new("");
key_name = g_string_new(NULL);
View
@@ -67,12 +67,33 @@ INIFile * open_ini_file (VFSFile * file)
gpointer section_hash, key_hash;
gsize off = 0;
+ gchar * buffer = NULL;
gint64 filesize = vfs_fsize (file);
+
+ if (filesize > 0)
+ {
+ buffer = g_malloc (filesize);
+ filesize = vfs_fread (buffer, 1, filesize, file);
+ }
+ else
+ {
+ gint64 readed;
+ filesize = 0;
+
+ do
+ {
+ buffer = g_realloc (buffer, filesize + 4096);
+ readed = vfs_fread (buffer + filesize, 1, 4096, file);
+ filesize += readed;
+ }
+ while (readed > 0);
+ }
+
if (filesize < 1)
+ {
+ g_free (buffer);
return NULL;
-
- gchar * buffer = g_malloc (filesize);
- filesize = vfs_fread (buffer, 1, filesize, file);
+ }
section_name = g_string_new("");
key_name = g_string_new(NULL);

0 comments on commit 47dcc58

Please sign in to comment.