]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccache.c
With no args, fc-cat now dumps all directories.
[fontconfig.git] / src / fccache.c
index 1411766fadcfec7e60c51ce1e875eb98fdb615af..378e39e1879023d7504a9c5e6c00be26d0df3ef4 100644 (file)
@@ -197,7 +197,7 @@ FcCacheRead (FcConfig *config)
 static FcBool
 FcDirCacheProcess (FcConfig *config, const FcChar8 *dir, 
                   FcBool (*callback) (int fd, off_t size, void *closure),
-                  void *closure)
+                  void *closure, FcChar8 **cache_file_ret)
 {
     int                fd = -1;
     FcChar8    cache_base[CACHEBASE_LEN];
@@ -221,7 +221,6 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
         if (!cache_hashed)
            break;
         fd = open((char *) cache_hashed, O_RDONLY | O_BINARY);
-       FcStrFree (cache_hashed);
         if (fd >= 0) {
            if (fstat (fd, &file_stat) >= 0 &&
                dir_stat.st_mtime <= file_stat.st_mtime)
@@ -229,19 +228,24 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
                ret = (*callback) (fd, file_stat.st_size, closure);
                if (ret)
                {
+                   if (cache_file_ret)
+                       *cache_file_ret = cache_hashed;
+                   else
+                       FcStrFree (cache_hashed);
                    close (fd);
                    break;
                }
            }
            close (fd);
        }
+       FcStrFree (cache_hashed);
     }
     FcStrListDone (list);
     
     return ret;
 }
 
-static FcBool
+FcBool
 FcDirCacheLoad (int fd, off_t size, void *closure)
 {
     FcCache    *cache;
@@ -303,13 +307,15 @@ FcDirCacheLoad (int fd, off_t size, void *closure)
 }
 
 FcCache *
-FcDirCacheMap (int fd, off_t size)
+FcDirCacheMap (const FcChar8 *dir, FcConfig *config, FcChar8 **cache_file)
 {
-    FcCache *cache;
+    FcCache *cache = NULL;
 
-    if (FcDirCacheLoad (fd, size, &cache))
-       return cache;
-    return NULL;
+    if (!FcDirCacheProcess (config, dir,
+                           FcDirCacheLoad,
+                           &cache, cache_file))
+       return NULL;
+    return cache;
 }
 
 FcBool
@@ -322,9 +328,8 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
     intptr_t   *cache_dirs;
     FcPattern   **cache_fonts;
 
-    if (!FcDirCacheProcess (config, dir, 
-                           FcDirCacheLoad,
-                           &cache))
+    cache = FcDirCacheMap (dir, config, NULL);
+    if (!cache)
        return FcFalse;
     
     cache_set = FcCacheSet (cache);
@@ -377,7 +382,7 @@ FcDirCacheValidate (int fd, off_t size, void *closure)
 FcBool
 FcDirCacheValid (const FcChar8 *dir, FcConfig *config)
 {
-    return FcDirCacheProcess (config, dir, FcDirCacheValidate, NULL);
+    return FcDirCacheProcess (config, dir, FcDirCacheValidate, NULL, NULL);
 }
 
 void