summaryrefslogtreecommitdiff
path: root/gtk/gtkiconcache.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2007-05-01 20:00:17 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2007-05-01 20:00:17 +0000
commit2a80113304da3afab9b9d6930a95427e35a83af6 (patch)
tree1ec7be2b5a2cda68885043e8dc861b9c5b8c5563 /gtk/gtkiconcache.c
parent6bade15e6051bec14c70af1b9568091db4b35730 (diff)
downloadgtk+-2a80113304da3afab9b9d6930a95427e35a83af6.tar.gz
Add an icon cache validator.
2007-05-01 Matthias Clasen <mclasen@redhat.com> * gtk/gtkiconcachvalidator.[hc]: Add an icon cache validator. * gtk/updateiconcache.c: Validate the generated cache before moving it in place. Also add a --validate option to validate an existing icon cache. * gtk/gtkiconcache.c: Validate icon caches before using them. * gtk/Makefile.am: Integrate it. svn path=/trunk/; revision=17753
Diffstat (limited to 'gtk/gtkiconcache.c')
-rw-r--r--gtk/gtkiconcache.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c
index a15d8d39c3..cd25d300f1 100644
--- a/gtk/gtkiconcache.c
+++ b/gtk/gtkiconcache.c
@@ -21,6 +21,7 @@
#include "gtkdebug.h"
#include "gtkiconcache.h"
+#include "gtkiconcachevalidator.h"
#include "gtkalias.h"
#include <glib/gstdio.h>
@@ -58,7 +59,7 @@ struct _GtkIconCache {
GtkIconCache *
_gtk_icon_cache_ref (GtkIconCache *cache)
{
- cache->ref_count ++;
+ cache->ref_count++;
return cache;
}
@@ -89,6 +90,7 @@ _gtk_icon_cache_new_for_path (const gchar *path)
struct stat st;
struct stat path_st;
gchar *buffer = NULL;
+ CacheInfo info;
/* Check if we have a cache file */
cache_filename = g_build_filename (path, "icon-theme.cache", NULL);
@@ -121,25 +123,26 @@ _gtk_icon_cache_new_for_path (const gchar *path)
if (!map)
goto done;
- /* Verify version */
- buffer = g_mapped_file_get_contents (map);
- if (GET_UINT16 (buffer, 0) != MAJOR_VERSION ||
- GET_UINT16 (buffer, 2) != MINOR_VERSION)
+ info.cache = g_mapped_file_get_contents (map);
+ info.cache_size = g_mapped_file_get_length (map);
+ info.n_directories = 0;
+ info.flags = CHECK_OFFSETS|CHECK_STRINGS;
+
+ g_print ("validating %s\n", cache_filename);
+ if (!_gtk_icon_cache_validate (&info))
{
g_mapped_file_free (map);
- GTK_NOTE (ICONTHEME,
- g_print ("wrong cache version\n"));
+ GTK_NOTE (ICONTHEME, g_print ("invalid icon cache\n"));
goto done;
}
- GTK_NOTE (ICONTHEME,
- g_print ("found cache for %s\n", path));
+ GTK_NOTE (ICONTHEME, g_print ("found cache for %s\n", path));
cache = g_new0 (GtkIconCache, 1);
cache->ref_count = 1;
cache->map = map;
- cache->buffer = buffer;
+ cache->buffer = g_mapped_file_get_contents (map);
done:
g_free (cache_filename);
@@ -440,7 +443,7 @@ _gtk_icon_cache_get_icon (GtkIconCache *cache,
length = GET_UINT32 (cache->buffer, pixel_data_offset + 4);
if (!gdk_pixdata_deserialize (&pixdata, length,
- cache->buffer + pixel_data_offset + 8,
+ (guchar *)(cache->buffer + pixel_data_offset + 8),
&error))
{
GTK_NOTE (ICONTHEME,