Use GMappedFile.

2005-06-27  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkiconcache.c (_gtk_icon_cache_new_for_path): Use
	GMappedFile.

	* configure.in: Require GLib 2.7.1
This commit is contained in:
Matthias Clasen 2005-06-27 04:49:03 +00:00 committed by Matthias Clasen
parent 1b8d849b36
commit d4c43a42ad
5 changed files with 39 additions and 66 deletions

View File

@ -1,3 +1,10 @@
2005-06-27 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkiconcache.c (_gtk_icon_cache_new_for_path): Use
GMappedFile.
* configure.in: Require GLib 2.7.1
2005-06-26 Matthias Clasen <mclasen@redhat.com> 2005-06-26 Matthias Clasen <mclasen@redhat.com>
* modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize): * modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize):

View File

@ -1,3 +1,10 @@
2005-06-27 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkiconcache.c (_gtk_icon_cache_new_for_path): Use
GMappedFile.
* configure.in: Require GLib 2.7.1
2005-06-26 Matthias Clasen <mclasen@redhat.com> 2005-06-26 Matthias Clasen <mclasen@redhat.com>
* modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize): * modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize):

View File

@ -1,3 +1,10 @@
2005-06-27 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkiconcache.c (_gtk_icon_cache_new_for_path): Use
GMappedFile.
* configure.in: Require GLib 2.7.1
2005-06-26 Matthias Clasen <mclasen@redhat.com> 2005-06-26 Matthias Clasen <mclasen@redhat.com>
* modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize): * modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize):

View File

@ -31,7 +31,7 @@ m4_define([gtk_api_version], [2.0])
m4_define([gtk_binary_version], [2.4.0]) m4_define([gtk_binary_version], [2.4.0])
# required versions of other packages # required versions of other packages
m4_define([glib_required_version], [2.7.0]) m4_define([glib_required_version], [2.7.1])
m4_define([pango_required_version], [1.9.0]) m4_define([pango_required_version], [1.9.0])
m4_define([atk_required_version], [1.0.1]) m4_define([atk_required_version], [1.0.1])

View File

@ -18,34 +18,25 @@
*/ */
#include <config.h> #include <config.h>
#include "gtkdebug.h" #include "gtkdebug.h"
#include "gtkiconcache.h" #include "gtkiconcache.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <gdk-pixbuf/gdk-pixdata.h> #include <gdk-pixbuf/gdk-pixdata.h>
#ifdef HAVE_MMAP
#include <sys/mman.h>
#endif
#ifdef G_OS_WIN32
#include <windows.h>
#include <io.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h> #include <string.h>
#ifndef _O_BINARY #ifndef _O_BINARY
#define _O_BINARY 0 #define _O_BINARY 0
#endif #endif
#ifndef MAP_FAILED
#define MAP_FAILED ((void *) -1)
#endif
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
@ -55,11 +46,8 @@
struct _GtkIconCache { struct _GtkIconCache {
gint ref_count; gint ref_count;
gsize size; GMappedFile *map;
gchar *buffer; gchar *buffer;
#ifdef G_OS_WIN32
HANDLE handle;
#endif
}; };
GtkIconCache * GtkIconCache *
@ -78,13 +66,8 @@ _gtk_icon_cache_unref (GtkIconCache *cache)
{ {
GTK_NOTE (ICONTHEME, GTK_NOTE (ICONTHEME,
g_print ("unmapping icon cache\n")); g_print ("unmapping icon cache\n"));
#ifdef HAVE_MMAP
munmap (cache->buffer, cache->size); g_mapped_file_free (cache->map);
#endif
#ifdef G_OS_WIN32
UnmapViewOfFile (cache->buffer);
CloseHandle (cache->handle);
#endif
g_free (cache); g_free (cache);
} }
} }
@ -93,16 +76,13 @@ GtkIconCache *
_gtk_icon_cache_new_for_path (const gchar *path) _gtk_icon_cache_new_for_path (const gchar *path)
{ {
GtkIconCache *cache = NULL; GtkIconCache *cache = NULL;
GMappedFile *map;
#if defined(HAVE_MMAP) || defined(G_OS_WIN32)
gchar *cache_filename; gchar *cache_filename;
gint fd = -1; gint fd = -1;
struct stat st; struct stat st;
struct stat path_st; struct stat path_st;
gchar *buffer = NULL; gchar *buffer = NULL;
#ifdef G_OS_WIN32
HANDLE handle = NULL;
#endif
/* Check if we have a cache file */ /* Check if we have a cache file */
cache_filename = g_build_filename (path, "icon-theme.cache", NULL); cache_filename = g_build_filename (path, "icon-theme.cache", NULL);
@ -110,9 +90,6 @@ _gtk_icon_cache_new_for_path (const gchar *path)
GTK_NOTE (ICONTHEME, GTK_NOTE (ICONTHEME,
g_print ("look for cache in %s\n", path)); g_print ("look for cache in %s\n", path));
if (!g_file_test (cache_filename, G_FILE_TEST_IS_REGULAR))
goto done;
if (g_stat (path, &path_st) < 0) if (g_stat (path, &path_st) < 0)
goto done; goto done;
@ -120,10 +97,7 @@ _gtk_icon_cache_new_for_path (const gchar *path)
fd = g_open (cache_filename, O_RDONLY|_O_BINARY, 0); fd = g_open (cache_filename, O_RDONLY|_O_BINARY, 0);
if (fd < 0) if (fd < 0)
{ goto done;
g_free (cache_filename);
return NULL;
}
if (fstat (fd, &st) < 0 || st.st_size < 4) if (fstat (fd, &st) < 0 || st.st_size < 4)
goto done; goto done;
@ -136,36 +110,18 @@ _gtk_icon_cache_new_for_path (const gchar *path)
goto done; goto done;
} }
#ifndef G_OS_WIN32 map = g_mapped_file_new (cache_filename, FALSE, NULL);
buffer = (gchar *) mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (buffer == MAP_FAILED) if (!map)
goto done; goto done;
#else
handle = CreateFileMapping (_get_osfhandle (fd), NULL, PAGE_READONLY,
0, 0, NULL);
if (handle == NULL)
goto done;
buffer = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, 0);
if (buffer == NULL)
{
CloseHandle (handle);
goto done;
}
#endif
/* Verify version */ /* Verify version */
buffer = g_mapped_file_get_contents (map);
if (GET_UINT16 (buffer, 0) != MAJOR_VERSION || if (GET_UINT16 (buffer, 0) != MAJOR_VERSION ||
GET_UINT16 (buffer, 2) != MINOR_VERSION) GET_UINT16 (buffer, 2) != MINOR_VERSION)
{ {
#ifndef G_OS_WIN32 g_mapped_file_free (map);
munmap (buffer, st.st_size);
#else
UnmapViewOfFile (buffer);
CloseHandle (handle);
#endif
GTK_NOTE (ICONTHEME, GTK_NOTE (ICONTHEME,
g_print ("wrong cache version\n")); g_print ("wrong cache version\n"));
goto done; goto done;
@ -176,18 +132,14 @@ _gtk_icon_cache_new_for_path (const gchar *path)
cache = g_new0 (GtkIconCache, 1); cache = g_new0 (GtkIconCache, 1);
cache->ref_count = 1; cache->ref_count = 1;
cache->map = map;
cache->buffer = buffer; cache->buffer = buffer;
#ifdef G_OS_WIN32
cache->handle = handle;
#endif
cache->size = st.st_size;
done: done:
g_free (cache_filename); g_free (cache_filename);
if (fd != -1) if (fd >= 0)
close (fd); close (fd);
#endif /* HAVE_MMAP || G_OS_WIN32 */
return cache; return cache;
} }