Fix fc-cat again. Sigh.

Internal interfaces in cache management changed again...
This commit is contained in:
Keith Packard 2006-08-30 22:23:25 -07:00
parent 2d3387fd72
commit 76abb77f26
3 changed files with 41 additions and 24 deletions

View File

@ -273,6 +273,28 @@ bail2:
return FcFalse; 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 int
main (int argc, char **argv) main (int argc, char **argv)
{ {
@ -322,30 +344,21 @@ main (int argc, char **argv)
for (; i < argc; i++) for (; i < argc; i++)
{ {
int fd;
int j; int j;
off_t size; off_t size;
intptr_t *cache_dirs; intptr_t *cache_dirs;
if (FcFileIsDir ((const FcChar8 *)argv[i])) if (FcFileIsDir ((const FcChar8 *)argv[i]))
fd = FcDirCacheOpen (config, (const FcChar8 *) argv[i], &size); cache = FcDirCacheMap ((const FcChar8 *) argv[i], config);
else else
fd = FcCacheFileOpen (argv[i], &size); cache = FcCacheFileMap (argv[i]);
if (fd < 0) if (!cache)
{ {
perror (argv[i]); perror (argv[i]);
ret++; ret++;
continue; continue;
} }
cache = FcDirCacheMap (fd, size);
close (fd);
if (!cache)
{
fprintf (stderr, "%s: cannot map cache\n", argv[i]);
ret++;
continue;
}
dirs = FcStrSetCreate (); dirs = FcStrSetCreate ();
fs = FcCacheSet (cache); fs = FcCacheSet (cache);
cache_dirs = FcCacheDirs (cache); cache_dirs = FcCacheDirs (cache);

View File

@ -242,7 +242,7 @@ FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
} }
static FcBool static FcBool
FcDirCacheLoad (int fd, off_t size, void *closure) FcCacheLoad (int fd, off_t size, void *closure)
{ {
FcCache *cache; FcCache *cache;
FcBool allocated = FcFalse; FcBool allocated = FcFalse;
@ -303,13 +303,15 @@ FcDirCacheLoad (int fd, off_t size, void *closure)
} }
FcCache * FcCache *
FcDirCacheMap (int fd, off_t size) FcDirCacheMap (const FcChar8 *dir, FcConfig *config)
{ {
FcCache *cache; FcCache *cache = NULL;
if (FcDirCacheLoad (fd, size, &cache)) if (!FcDirCacheProcess (config, dir,
return cache; FcCacheLoad,
return NULL; &cache))
return NULL;
return cache;
} }
FcBool FcBool
@ -322,9 +324,8 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs,
intptr_t *cache_dirs; intptr_t *cache_dirs;
FcPattern **cache_fonts; FcPattern **cache_fonts;
if (!FcDirCacheProcess (config, dir, cache = FcDirCacheMap (dir, config);
FcDirCacheLoad, if (!cache)
&cache))
return FcFalse; return FcFalse;
cache_set = FcCacheSet (cache); cache_set = FcCacheSet (cache);

View File

@ -500,15 +500,18 @@ FcBool
FcDirCacheConsume (FILE *file, FcFontSet *set, FcStrSet *dirs, FcDirCacheConsume (FILE *file, FcFontSet *set, FcStrSet *dirs,
const FcChar8 *dir, char *dirname); const FcChar8 *dir, char *dirname);
FcCache *
FcDirCacheMap (int fd, off_t size);
void void
FcDirCacheUnmap (FcCache *cache); FcDirCacheUnmap (FcCache *cache);
FcBool FcBool
FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config); 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 */ /* fccfg.c */
FcBool FcBool