2013-01-10	Nicolas Setton  <setton@adacore.com>

	* gdk-pixbuf/gdk-pixbuf-io.c: When reading a module from the
	loaders.cache file, if the module is not found in the described
	location, attempt to find it in the module directory.

	* gdk-pixbuf/queryloaders.c: Write the base name of the modules
	in the loaders.cache file, to make it relocatable.

	For M109-016.

--- gdk-pixbuf/queryloaders.c.orig	2013-01-10 12:56:14.102690967 +0100
+++ gdk-pixbuf/queryloaders.c	2013-01-10 14:06:35.618051001 +0100
@@ -30,6 +30,7 @@
 
 #include <errno.h>
 #include <string.h>
+#include <libgen.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -124,8 +125,10 @@
         const GdkPixbufModulePattern *pattern;
         char **mime;
         char **ext;
+        gchar *base = basename (g_strdup (path));
+
+        g_string_append_printf (contents, "\"%s\"\n", base);
 
-        g_string_append_printf (contents, "\"%s\"\n", path);
         g_string_append_printf (contents, "\"%s\" %u \"%s\" \"%s\" \"%s\"\n",
                   info->name,
                   info->flags,
--- gdk-pixbuf/gdk-pixbuf-io.c.orig	2013-01-10 12:07:34.817630096 +0100
+++ gdk-pixbuf/gdk-pixbuf-io.c	2013-01-10 14:33:41.024250520 +0100
@@ -397,6 +397,17 @@
   return result;
 }
 
+static gchar *
+gdk_pixbuf_get_module_dir (void)
+{
+  gchar *result = g_strdup (g_getenv ("GDK_PIXBUF_MODULEDIR"));
+
+  if (!result)
+          result = g_build_filename (GDK_PIXBUF_LIBDIR, "gdk-pixbuf-2.0", GDK_PIXBUF_BINARY_VERSION, "loaders", NULL);
+
+  return result;
+}
+
 #endif  /* USE_GMODULE */
 
 
@@ -415,6 +426,7 @@
         gboolean have_error = FALSE;
         GdkPixbufModule *module = NULL;
         gchar *filename = gdk_pixbuf_get_module_file ();
+        gchar *modules_dir = gdk_pixbuf_get_module_dir ();
         int flags;
         int n_patterns = 0;
         GdkPixbufModulePattern *pattern;
@@ -555,7 +567,22 @@
                                            filename, line_buf);
                                 have_error = TRUE;
                         }
+			
                         module->module_path = g_strdup (tmp_buf->str);
+			
+			/* Check for the existence of the module file */
+                        if (access (module->module_path, F_OK) == -1) {
+                           /* The module file was not found, attempt to
+                              find it in the module dir. 
+                           */
+                           g_free (module->module_path);          
+#ifdef G_OS_WIN32
+                           module->module_path = g_strjoin ("\\", modules_dir, tmp_buf->str, 0);
+#else
+                           module->module_path = g_strjoin ("/", modules_dir, tmp_buf->str, 0);
+#endif
+			}
+			
                 }
                 else if (!module->module_name) {
                         module->info = g_new0 (GdkPixbufFormat, 1);
@@ -658,6 +685,7 @@
         g_string_free (tmp_buf, TRUE);
         g_io_channel_unref (channel);
         g_free (filename);
+        g_free (modules_dir);
 #endif
 }
 
