]> git.wh0rd.org - fontconfig.git/commitdiff
Fix fc-cat again. Sigh.
authorKeith Packard <keithp@neko.keithp.com>
Thu, 31 Aug 2006 05:23:25 +0000 (22:23 -0700)
committerKeith Packard <keithp@neko.keithp.com>
Thu, 31 Aug 2006 05:23:25 +0000 (22:23 -0700)
Internal interfaces in cache management changed again...

fc-cat/fc-cat.c
src/fccache.c
src/fcint.h

index b988a29309382b58decc32e2dd5ddd400803fb19..c033bdc776359ec1886ddacb39612d21750220f3 100644 (file)
@@ -273,6 +273,28 @@ bail2:
     return FcFalse;
 }
 
+FcCache *
+FcCacheFileMap (const FcChar8 *file)
+{
+    FcCache *cache;
+    int            fd;
+    struct stat file_stat;
+
+    fd = open (file, O_RDONLY | O_BINARY);
+    if (fd < 0)
+       return NULL;
+    if (fstat (fd, &file_stat) < 0) {
+       close (fd);
+       return NULL;
+    }
+    if (FcCacheLoad (fd, file_stat.st_size, &cache)) {
+       close (fd);
+       return cache;
+    }
+    close (fd);
+    return NULL;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -322,30 +344,21 @@ main (int argc, char **argv)
 
     for (; i < argc; i++)
     {
-       int     fd;
        int     j;
        off_t   size;
        intptr_t        *cache_dirs;
        
        if (FcFileIsDir ((const FcChar8 *)argv[i]))
-           fd = FcDirCacheOpen (config, (const FcChar8 *) argv[i], &size);
+           cache = FcDirCacheMap ((const FcChar8 *) argv[i], config);
        else
-           fd = FcCacheFileOpen (argv[i], &size);
-       if (fd < 0)
+           cache = FcCacheFileMap (argv[i]);
+       if (!cache)
        {
            perror (argv[i]);
            ret++;
            continue;
        }
        
-       cache = FcDirCacheMap (fd, size);
-       close (fd);
-       if (!cache)
-       {
-           fprintf (stderr, "%s: cannot map cache\n", argv[i]);
-           ret++;
-           continue;
-       }
        dirs = FcStrSetCreate ();
        fs = FcCacheSet (cache);
        cache_dirs = FcCacheDirs (cache);
index 1411766fadcfec7e60c51ce1e875eb98fdb615af..646f03af8dacb42e9b1275288f630a6bb7265212 100644 (file)
@@ -242,7 +242,7 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
 }
 
 static FcBool
-FcDirCacheLoad (int fd, off_t size, void *closure)
+FcCacheLoad (int fd, off_t size, void *closure)
 {
     FcCache    *cache;
     FcBool     allocated = FcFalse;
@@ -303,13 +303,15 @@ FcDirCacheLoad (int fd, off_t size, void *closure)
 }
 
 FcCache *
-FcDirCacheMap (int fd, off_t size)
+FcDirCacheMap (const FcChar8 *dir, FcConfig *config)
 {
-    FcCache *cache;
+    FcCache *cache = NULL;
 
-    if (FcDirCacheLoad (fd, size, &cache))
-       return cache;
-    return NULL;
+    if (!FcDirCacheProcess (config, dir,
+                           FcCacheLoad,
+                           &cache))
+       return NULL;
+    return cache;
 }
 
 FcBool
@@ -322,9 +324,8 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
     intptr_t   *cache_dirs;
     FcPattern   **cache_fonts;
 
-    if (!FcDirCacheProcess (config, dir, 
-                           FcDirCacheLoad,
-                           &cache))
+    cache = FcDirCacheMap (dir, config);
+    if (!cache)
        return FcFalse;
     
     cache_set = FcCacheSet (cache);
index 96de69591f4f548d2562e309457867d2c1e42a0b..651ca6627a0e9632ae03e61312aceb03a89ae5fa 100644 (file)
@@ -500,15 +500,18 @@ FcBool
 FcDirCacheConsume (FILE *file, FcFontSet *set, FcStrSet *dirs,
                   const FcChar8 *dir, char *dirname);
     
-FcCache *
-FcDirCacheMap (int fd, off_t size);
-
 void
 FcDirCacheUnmap (FcCache *cache);
 
 FcBool
 FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
  
+FcCache *
+FcDirCacheMap (const FcChar8 *dir, FcConfig *config);
+    
+FcBool
+FcDirCacheLoad (int fd, off_t size, void *closure);
+
 /* fccfg.c */
 
 FcBool