]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccache.c
Fix intel compiler warnings: make many variables static, eliminate
[fontconfig.git] / src / fccache.c
index 6385d3ff672152e0e3c27e79eacba5233d6446b2..5aa0df894a3e491554b22a24976d7995d44dd070 100644 (file)
@@ -34,7 +34,7 @@
 #include <unistd.h>
 
 #define ENDIAN_TEST 0x12345678
-#define MACHINE_SIGNATURE_SIZE 9 + 5*20 + 1
+#define MACHINE_SIGNATURE_SIZE (9 + 5*20 + 1)
 
 #ifndef O_BINARY
 #define O_BINARY 0
@@ -206,7 +206,7 @@ FcGlobalCacheLoad (FcGlobalCache    *cache,
     current_arch_start = FcCacheSkipToArch(cache->fd, 
                                           current_arch_machine_name);
     if (current_arch_start < 0)
-        goto bail_and_destroy;
+        goto bail1;
 
     lseek (cache->fd, current_arch_start, SEEK_SET);
     if (!FcCacheReadString (cache->fd, candidate_arch_machine_name, 
@@ -410,7 +410,7 @@ FcGlobalCacheSave (FcGlobalCache    *cache,
                   const FcChar8    *cache_file,
                   FcConfig         *config)
 {
-    int                        fd, fd_orig, i;
+    int                        fd, fd_orig;
     FcGlobalCacheDir   *dir;
     FcAtomic           *atomic;
     off_t              current_arch_start = 0, truncate_to;
@@ -468,6 +468,8 @@ FcGlobalCacheSave (FcGlobalCache    *cache,
     truncate_to = current_arch_start + strlen(current_arch_machine_name) + 11;
     for (dir = cache->dirs; dir; dir = dir->next)
     {
+       int i;
+
        if (dir->state == FcGCDirDisabled)
            continue;
        truncate_to += strlen(dir->name) + 1;
@@ -488,6 +490,7 @@ FcGlobalCacheSave (FcGlobalCache    *cache,
 
     for (dir = cache->dirs; dir; dir = dir->next)
     {
+       int i;
        const char * d;
        off_t off;
 
@@ -634,7 +637,7 @@ FcCacheSkipToArch (int fd, const char * arch)
            return -1;
        bs = strtol(candidate_arch_machine_name_count, &candidate_arch, 16);
 
-       // count = 0 should probably be distinguished from the !bs condition
+       /* count = 0 should probably be distinguished from the !bs condition */
        if (!bs || bs < strlen (candidate_arch_machine_name_count))
            return -1;
 
@@ -643,9 +646,8 @@ FcCacheSkipToArch (int fd, const char * arch)
        if (strcmp (candidate_arch, arch)==0)
            return current_arch_start;
        current_arch_start += bs;
+       current_arch_start = FcCacheNextOffset (current_arch_start);
     }
-
-    return -1;
 }
 
 /* Cuts out the segment at the file pointer (moves everything else
@@ -760,6 +762,7 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir)
     off_t      current_arch_start;
     char       *current_arch_machine_name;
     FcCache    metadata;
+    char       subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
 
     fd = FcDirCacheOpen (dir);
     if (fd < 0)
@@ -770,17 +773,19 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir)
 
     if (current_arch_start >= 0)
     {
+       if (lseek (fd, current_arch_start, SEEK_SET) != current_arch_start)
+           goto bail1;
+
+       FcCacheSkipString (fd);
+
+       while (FcCacheReadString (fd, subdirName, sizeof (subdirName)) && strlen (subdirName) > 0)
+           ;
+
         if (read(fd, &metadata, sizeof(FcCache)) != sizeof(FcCache))
-        {
-            close (fd);
-            return FcFalse;
-        }
+           goto bail1;
 
         if (metadata.magic != FC_CACHE_MAGIC)
-        {
-            close (fd);
-            return FcFalse;
-        }
+           goto bail1;
     }
 
     close (fd);
@@ -790,6 +795,8 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir)
     
     return FcTrue;
 
+ bail1:
+    close (fd);
  bail:
     return FcFalse;
 }
@@ -926,7 +933,9 @@ FcCacheReadDirs (FcConfig * config, FcGlobalCache * cache,
            FcStrSetDestroy (subdirs);
            continue;
        }
-       if (FcDirCacheValid (dir) && FcDirCacheRead (set, subdirs, dir, config))
+       if (FcDirCacheValid (dir) && 
+           FcDirCacheHasCurrentArch (dir) && 
+           FcDirCacheRead (set, subdirs, dir, config))
        {
            /* if an old entry is found in the global cache, disable it */
            if ((d = FcGlobalCacheDirFind (cache, (const char *)dir)) != NULL)
@@ -1199,7 +1208,7 @@ FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
     current_dir_block = malloc (metadata->count);
     if (!current_dir_block)
        goto bail;
-    // shut up valgrind
+    /* shut up valgrind */
     memset (current_dir_block, 0, metadata->count);
     final_dir_block = FcFontSetDistributeBytes (metadata, current_dir_block);
 
@@ -1316,8 +1325,8 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
 
     if (current_arch_start < 0)
     {
-       off_t i = lseek(fd_orig, 0, SEEK_END);
-       current_arch_start = FcCacheNextOffset (i);
+       off_t offset = lseek(fd_orig, 0, SEEK_END);
+       current_arch_start = FcCacheNextOffset (offset);
     }
 
     if (fd_orig != -1 && !FcCacheCopyOld(fd, fd_orig, current_arch_start))
@@ -1364,6 +1373,7 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
                 metadata.count)
            perror("write current_dir_block");
        free (current_dir_block);
+        current_dir_block = 0;
     }
 
     /* this actually serves to pad out the cache file, if needed */