From 76abb77f26c43d069919f80e960c71c2242fb5c2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 30 Aug 2006 22:23:25 -0700 Subject: Fix fc-cat again. Sigh. Internal interfaces in cache management changed again... --- fc-cat/fc-cat.c | 37 +++++++++++++++++++++++++------------ src/fccache.c | 19 ++++++++++--------- src/fcint.h | 9 ++++++--- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c index b988a29..c033bdc 100644 --- a/fc-cat/fc-cat.c +++ b/fc-cat/fc-cat.c @@ -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); diff --git a/src/fccache.c b/src/fccache.c index 1411766..646f03a 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -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); diff --git a/src/fcint.h b/src/fcint.h index 96de695..651ca66 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -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 -- cgit v1.2.3