]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccache.c
Add *NeededBytesAlign(), which overestimates the padding which is later
[fontconfig.git] / src / fccache.c
index a513652025d4ad43c6d050b1d4c2112161a7cfc0..af8a318c43e4f5743b693b548f9f16bbc458e9fe 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 #include "fcint.h"
+#include <unistd.h>
 
 #define ENDIAN_TEST 0x12345678
-#define MACHINE_SIGNATURE_SIZE 9 + 5*19 + 1
+#define MACHINE_SIGNATURE_SIZE 9 + 5*20 + 1
 
 static off_t
 FcCacheSkipToArch (int fd, const char * arch);
@@ -152,10 +153,12 @@ FcGlobalCacheDestroy (FcGlobalCache *cache)
 void
 FcGlobalCacheLoad (FcGlobalCache    *cache,
                    FcStrSet        *staleDirs,
-                  const FcChar8    *cache_file)
+                  const FcChar8    *cache_file,
+                  FcConfig         *config)
 {
     char               name_buf[8192];
     FcGlobalCacheDir   *d, *next;
+    FcFileTime         config_time = FcConfigModifiedTime (config);
     char               * current_arch_machine_name;
     char               candidate_arch_machine_name[MACHINE_SIGNATURE_SIZE + 9];
     off_t              current_arch_start;
@@ -191,8 +194,11 @@ FcGlobalCacheLoad (FcGlobalCache    *cache,
        if (!strlen(name_buf))
            break;
 
+       /* Directory must be older than the global cache file; also
+          cache must be newer than the config file. */
         if (stat ((char *) name_buf, &dir_stat) < 0 || 
-            dir_stat.st_mtime > cache_stat.st_mtime)
+            dir_stat.st_mtime > cache_stat.st_mtime ||
+           (config_time.set && cache_stat.st_mtime < config_time.time))
         {
             FcCache md;
 
@@ -412,7 +418,6 @@ FcGlobalCacheSave (FcGlobalCache    *cache,
     return FcFalse;
 }
 
-#define PAGESIZE 8192
 /* 
  * Find the next presumably-mmapable offset after the supplied file
  * position.
@@ -420,10 +425,13 @@ FcGlobalCacheSave (FcGlobalCache    *cache,
 static int
 FcCacheNextOffset(off_t w)
 {
-    if (w % PAGESIZE == 0) 
+    static long pagesize = -1;
+    if (pagesize == -1)
+       pagesize = sysconf(_SC_PAGESIZE);
+    if (w % pagesize == 0) 
        return w;
     else
-       return ((w / PAGESIZE)+1)*PAGESIZE;
+       return ((w / pagesize)+1)*pagesize;
 }
 
 /* return the address of the segment for the provided arch,
@@ -553,8 +561,9 @@ FcDirCacheValid (const FcChar8 *dir)
      * If the directory has been modified more recently than
      * the cache file, the cache is not valid
      */
-    if (dir_stat.st_mtime - file_stat.st_mtime > 0)
+    if (dir_stat.st_mtime > file_stat.st_mtime)
         return FcFalse;
+
     return FcTrue;
 }
 
@@ -795,7 +804,8 @@ FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
 
     memset (metadata, 0, sizeof(FcCache));
     FcFontSetNewBank();
-    metadata->count = FcFontSetNeededBytes (set);
+    metadata->count = FcFontSetNeededBytes (set) + 
+       FcFontSetNeededBytesAlign ();
     metadata->magic = FC_CACHE_MAGIC;
     metadata->bank = bank;
 
@@ -937,12 +947,12 @@ static char *
 FcCacheMachineSignature ()
 {
     static char buf[MACHINE_SIGNATURE_SIZE];
-    int magic = ENDIAN_TEST;
+    int32_t magic = ENDIAN_TEST;
     char * m = (char *)&magic;
 
     sprintf (buf, "%2x%2x%2x%2x "
             "%4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x "
-            "%4x %4x %4x %4x %4x %4x %4x\n", 
+            "%4x %4x %4x %4x %4x %4x %4x %4x\n", 
             m[0], m[1], m[2], m[3],
             (unsigned int)sizeof (char),
             (unsigned int)sizeof (char *),
@@ -962,7 +972,8 @@ FcCacheMachineSignature ()
             (unsigned int)sizeof (FcChar16),
             (unsigned int)sizeof (FcCharLeaf),
             (unsigned int)sizeof (FcChar32),
-            (unsigned int)sizeof (FcCache));
+            (unsigned int)sizeof (FcCache),
+            (unsigned int)sysconf(_SC_PAGESIZE));
 
     return buf;
 }