The point of the root support is to let fc-cache be usable on fs trees
other than just /. This is useful to people cross-compiling, and for
non-root building (chroot won't work) for distro maintainers. So now
we can tell fontconfig to search a specific root path to locate all of
its configs/fonts/caches/etc... without having to modify the configs.
We have to add a few new helper options for setting/getting the config
root, and then extend some of the existing API funcs to take a config
struct as an option. This way the low level pieces know which paths
to actually search.
First we export the internal FcStat helper. The fc-cache code uses
stat() directly, but we already have a FcStat helper to workaround
misc issues, so just use that one instead.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
const struct option longopts[] = {
{"force", 0, 0, 'f'},
{"really-force", 0, 0, 'r'},
const struct option longopts[] = {
{"force", 0, 0, 'f'},
{"really-force", 0, 0, 'r'},
{"system-only", 0, 0, 's'},
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"system-only", 0, 0, 's'},
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
- fprintf (file, "usage: %s [-frsvVh] [--force|--really-force] [--system-only] [--verbose] [--version] [--help] [dirs]\n",
+ fprintf (file, "usage: %s [-frRsvVh] [--force|--really-force] [--root <root>] [--system-only] [--verbose] [--version] [--help] [dirs]\n",
- fprintf (file, "usage: %s [-frsvVh] [dirs]\n",
+ fprintf (file, "usage: %s [-frRsvVh] [dirs]\n",
program);
#endif
fprintf (file, "Build font information caches in [dirs]\n"
program);
#endif
fprintf (file, "Build font information caches in [dirs]\n"
#if HAVE_GETOPT_LONG
fprintf (file, " -f, --force scan directories with apparently valid caches\n");
fprintf (file, " -r, --really-force erase all existing caches, then rescan\n");
#if HAVE_GETOPT_LONG
fprintf (file, " -f, --force scan directories with apparently valid caches\n");
fprintf (file, " -r, --really-force erase all existing caches, then rescan\n");
+ fprintf (file, " -R, --root <root> change to <root> before loading files\n");
fprintf (file, " -s, --system-only scan system-wide directories only\n");
fprintf (file, " -v, --verbose display status information while busy\n");
fprintf (file, " -V, --version display font config version and exit\n");
fprintf (file, " -s, --system-only scan system-wide directories only\n");
fprintf (file, " -v, --verbose display status information while busy\n");
fprintf (file, " -V, --version display font config version and exit\n");
#else
fprintf (file, " -f (force) scan directories with apparently valid caches\n");
fprintf (file, " -r, (really force) erase all existing caches, then rescan\n");
#else
fprintf (file, " -f (force) scan directories with apparently valid caches\n");
fprintf (file, " -r, (really force) erase all existing caches, then rescan\n");
+ fprintf (file, " -R <root> (root) change to <root> before loading files\n");
fprintf (file, " -s (system) scan system-wide directories only\n");
fprintf (file, " -v (verbose) display status information while busy\n");
fprintf (file, " -V (version) display font config version and exit\n");
fprintf (file, " -s (system) scan system-wide directories only\n");
fprintf (file, " -v (verbose) display status information while busy\n");
fprintf (file, " -V (version) display font config version and exit\n");
- if (stat ((char *) dir, &statb) == -1)
+ if (FcStat (config, dir, &statb) == -1)
{
switch (errno) {
case ENOENT:
{
switch (errno) {
case ENOENT:
{
DIR *d;
struct dirent *ent;
{
DIR *d;
struct dirent *ent;
+ FcChar8 *fullDir;
+ FcChar8 *checkDir;
FcBool ret = FcTrue;
FcBool remove;
FcCache *cache;
struct stat target_stat;
FcBool ret = FcTrue;
FcBool remove;
FcCache *cache;
struct stat target_stat;
- if (access ((char *) dir, W_OK) != 0)
+ fullDir = FcConfigGetRootPlus (config, dir);
+ if (fullDir)
+ checkDir = fullDir;
+ else
+ checkDir = dir;
+
+ if (access ((char *) checkDir, W_OK) != 0)
{
if (verbose)
printf ("%s: not cleaning %s cache directory\n", dir,
access ((char *) dir, F_OK) == 0 ? "unwritable" : "non-existent");
{
if (verbose)
printf ("%s: not cleaning %s cache directory\n", dir,
access ((char *) dir, F_OK) == 0 ? "unwritable" : "non-existent");
}
if (verbose)
printf ("%s: cleaning cache directory\n", dir);
}
if (verbose)
printf ("%s: cleaning cache directory\n", dir);
- d = opendir ((char *) dir);
+ d = opendir ((char *) checkDir);
if (!d)
{
perror ((char *) dir);
if (!d)
{
perror ((char *) dir);
+ ret = FcFalse;
+ goto done;
}
while ((ent = readdir (d)))
{
}
while ((ent = readdir (d)))
{
break;
}
remove = FcFalse;
break;
}
remove = FcFalse;
- cache = FcDirCacheLoadFile (file_name, NULL);
+ cache = FcDirCacheLoadFile2 (file_name, config, NULL);
if (!cache)
{
if (verbose)
if (!cache)
{
if (verbose)
else
{
target_dir = FcCacheDir (cache);
else
{
target_dir = FcCacheDir (cache);
- if (stat ((char *) target_dir, &target_stat) < 0)
+ if (FcStat (config, target_dir, &target_stat) < 0)
{
if (verbose)
printf ("%s: %s: missing directory: %s \n",
{
if (verbose)
printf ("%s: %s: missing directory: %s \n",
- if (unlink ((char *) file_name) < 0)
+ FcChar8 *unlink_file = FcConfigGetRootPlus (config, file_name);
+ if (!unlink_file)
+ unlink_file = file_name;
+ if (unlink ((char *) unlink_file) < 0)
- perror ((char *) file_name);
+ perror ((char *) unlink_file);
+ if (unlink_file != file_name)
+ FcStrFree (unlink_file);
}
FcDirCacheUnload (cache);
FcStrFree (file_name);
}
closedir (d);
}
FcDirCacheUnload (cache);
FcStrFree (file_name);
}
closedir (d);
+ done:
+ if (fullDir)
+ FcStrFree (fullDir);
FcBool really_force = FcFalse;
FcBool systemOnly = FcFalse;
FcConfig *config;
FcBool really_force = FcFalse;
FcBool systemOnly = FcFalse;
FcConfig *config;
int i;
int changed;
int ret;
int i;
int changed;
int ret;
int c;
#if HAVE_GETOPT_LONG
int c;
#if HAVE_GETOPT_LONG
- while ((c = getopt_long (argc, argv, "frsVvh", longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "frR:sVvh", longopts, NULL)) != -1)
- while ((c = getopt (argc, argv, "frsVvh")) != -1)
+ while ((c = getopt (argc, argv, "frR:sVvh")) != -1)
case 'f':
force = FcTrue;
break;
case 'f':
force = FcTrue;
break;
+ case 'R':
+ rootDir = optarg;
+ break;
case 's':
systemOnly = FcTrue;
break;
case 's':
systemOnly = FcTrue;
break;
return 1;
}
FcConfigSetCurrent (config);
return 1;
}
FcConfigSetCurrent (config);
+ FcConfigSetRoot (config, (const FcChar8 *) rootDir);
<cmdsynopsis>
<command>&dhpackage;</command>
<cmdsynopsis>
<command>&dhpackage;</command>
- <arg><option>-frsvVh</option></arg>
+ <arg><option>-frRsvVh</option></arg>
<arg><option>--force</option></arg>
<arg><option>--really-force</option></arg>
<arg><option>--force</option></arg>
<arg><option>--really-force</option></arg>
+ <arg><option>--root</option></arg>
<arg><option>--system-only</option></arg>
<arg><option>--verbose</option></arg>
<arg><option>--version</option></arg>
<arg><option>--system-only</option></arg>
<arg><option>--verbose</option></arg>
<arg><option>--version</option></arg>
<para>Erase all existing cache files and rescan.</para>
</listitem>
</varlistentry>
<para>Erase all existing cache files and rescan.</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-R</option>
+ <option>--root</option>
+ </term>
+ <listitem>
+ <para>Change to root before loading files.</para>
+ </listitem>
+ </varlistentry>
<varlistentry>
<term><option>-s</option>
<option>--system-only</option>
<varlistentry>
<term><option>-s</option>
<option>--system-only</option>
FcChar8 *cache_file = NULL;
struct stat file_stat;
FcChar8 *cache_file = NULL;
struct stat file_stat;
+ if (FcFileIsDir2 (config, arg))
cache = FcDirCacheLoad (arg, config, &cache_file);
else
cache = FcDirCacheLoad (arg, config, &cache_file);
else
- cache = FcDirCacheLoadFile (arg, &file_stat);
+ cache = FcDirCacheLoadFile2 (arg, config, &file_stat);
if (!cache)
{
perror ((char *) arg);
if (!cache)
{
perror ((char *) arg);
+FcPublic int
+FcStat (FcConfig *config, const FcChar8 *file, struct stat *statb);
+
FcPublic const FcChar8 *
FcCacheDir(const FcCache *c);
FcPublic const FcChar8 *
FcCacheDir(const FcCache *c);
FcPublic FcChar8 *
FcConfigFilename (const FcChar8 *url);
FcPublic FcChar8 *
FcConfigFilename (const FcChar8 *url);
+
+FcPublic FcChar8 *
+FcConfigFilename2 (FcConfig *config, const FcChar8 *url);
FcPublic FcConfig *
FcConfigCreate (void);
FcPublic FcConfig *
FcConfigCreate (void);
FcPattern *p,
FcMatchKind kind);
FcPattern *p,
FcMatchKind kind);
+FcPublic void
+FcConfigSetRoot (FcConfig *config,
+ const FcChar8 *path);
+
+FcPublic const FcChar8 *
+FcConfigGetRoot (FcConfig *config);
+
+FcPublic FcChar8 *
+FcConfigGetRootPlus (FcConfig *config,
+ const FcChar8 *path);
+
/* fccharset.c */
FcPublic FcCharSet*
FcCharSetCreate (void);
/* fccharset.c */
FcPublic FcCharSet*
FcCharSetCreate (void);
FcPublic FcBool
FcFileIsDir (const FcChar8 *file);
FcPublic FcBool
FcFileIsDir (const FcChar8 *file);
+FcPublic FcBool
+FcFileIsDir2 (FcConfig *config, const FcChar8 *file);
+
FcPublic FcBool
FcFileScan (FcFontSet *set,
FcStrSet *dirs,
FcPublic FcBool
FcFileScan (FcFontSet *set,
FcStrSet *dirs,
FcPublic FcCache *
FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat);
FcPublic FcCache *
FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat);
+FcPublic FcCache *
+FcDirCacheLoadFile2 (const FcChar8 *cache_file, FcConfig *config, struct stat *file_stat);
+
FcPublic void
FcDirCacheUnload (FcCache *cache);
FcPublic void
FcDirCacheUnload (FcCache *cache);
FcPublic FcPattern *
FcFreeTypeQuery (const FcChar8 *file, int id, FcBlanks *blanks, int *count);
FcPublic FcPattern *
FcFreeTypeQuery (const FcChar8 *file, int id, FcBlanks *blanks, int *count);
+FcPublic FcPattern *
+FcFreeTypeQuery2 (FcConfig *config, const FcChar8 *file, int id, FcBlanks *blanks, int *count);
+
/* fcfs.c */
FcPublic FcFontSet *
/* fcfs.c */
FcPublic FcFontSet *
FcPublic FcBool
FcAtomicLock (FcAtomic *atomic);
FcPublic FcBool
FcAtomicLock (FcAtomic *atomic);
+FcPublic FcBool
+FcAtomicLock2 (FcConfig *config, FcAtomic *atomic);
+
FcPublic FcChar8 *
FcAtomicNewFile (FcAtomic *atomic);
FcPublic FcChar8 *
FcAtomicNewFile (FcAtomic *atomic);
FcBool
FcAtomicLock (FcAtomic *atomic)
FcBool
FcAtomicLock (FcAtomic *atomic)
+{
+ return FcAtomicLock2 (FcConfigGetCurrent (), atomic);
+}
+
+FcBool
+FcAtomicLock2 (FcConfig *config, FcAtomic *atomic)
{
int fd = -1;
FILE *f = 0;
{
int fd = -1;
FILE *f = 0;
* machines sharing the same filesystem will have clocks
* reasonably close to each other.
*/
* machines sharing the same filesystem will have clocks
* reasonably close to each other.
*/
- if (FcStat (atomic->lck, &lck_stat) >= 0)
+ if (FcStat (config, atomic->lck, &lck_stat) >= 0)
{
time_t now = time (0);
if ((long int) (now - lck_stat.st_mtime) > 10 * 60)
{
#ifdef HAVE_LINK
if (unlink ((char *) atomic->lck) == 0)
{
time_t now = time (0);
if ((long int) (now - lck_stat.st_mtime) > 10 * 60)
{
#ifdef HAVE_LINK
if (unlink ((char *) atomic->lck) == 0)
- return FcAtomicLock (atomic);
+ return FcAtomicLock2 (config, atomic);
#else
if (rmdir ((char *) atomic->lck) == 0)
#else
if (rmdir ((char *) atomic->lck) == 0)
- return FcAtomicLock (atomic);
+ return FcAtomicLock2 (config, atomic);
-FcStat (const FcChar8 *file, struct stat *statb)
+FcStat (FcConfig *config, const FcChar8 *file, struct stat *statb)
{
WIN32_FILE_ATTRIBUTE_DATA wfad;
char full_path_name[MAX_PATH];
{
WIN32_FILE_ATTRIBUTE_DATA wfad;
char full_path_name[MAX_PATH];
-FcStat (const FcChar8 *file, struct stat *statb)
+FcStat (FcConfig *config, const FcChar8 *file, struct stat *statb)
- return stat ((char *) file, statb);
+ int ret;
+ FcChar8 *fullFile = FcConfigGetRootPlus (config, file);
+
+ if (fullFile)
+ file = fullFile;
+ ret = stat ((char *) file, statb);
+ if (fullFile)
+ FcStrFree (fullFile);
+
+ return ret;
-FcDirCacheOpenFile (const FcChar8 *cache_file, struct stat *file_stat)
+FcDirCacheOpenFile (FcConfig *config, const FcChar8 *cache_file, struct stat *file_stat)
- if (FcStat (cache_file, file_stat) < 0)
+ if (FcStat (config, cache_file, file_stat) < 0)
- fd = open((char *) cache_file, O_RDONLY | O_BINARY);
+ fullFile = FcConfigGetRootPlus (config, cache_file);
+ if (fullFile)
+ cache_file = fullFile;
+ fd = open ((char *) cache_file, O_RDONLY | O_BINARY);
+ if (fullFile)
+ FcStrFree (fullFile);
if (fd < 0)
return fd;
#ifndef _WIN32
if (fd < 0)
return fd;
#ifndef _WIN32
*/
static FcBool
FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
*/
static FcBool
FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
- FcBool (*callback) (int fd, struct stat *fd_stat,
+ FcBool (*callback) (FcConfig *config, int fd, struct stat *fd_stat,
struct stat *dir_stat, void *closure),
void *closure, FcChar8 **cache_file_ret)
{
struct stat *dir_stat, void *closure),
void *closure, FcChar8 **cache_file_ret)
{
struct stat file_stat, dir_stat;
FcBool ret = FcFalse;
struct stat file_stat, dir_stat;
FcBool ret = FcFalse;
- if (FcStat (dir, &dir_stat) < 0)
+ if (FcStat (config, dir, &dir_stat) < 0)
return FcFalse;
FcDirCacheBasename (dir, cache_base);
return FcFalse;
FcDirCacheBasename (dir, cache_base);
FcChar8 *cache_hashed = FcStrPlus (cache_dir, cache_base);
if (!cache_hashed)
break;
FcChar8 *cache_hashed = FcStrPlus (cache_dir, cache_base);
if (!cache_hashed)
break;
- fd = FcDirCacheOpenFile (cache_hashed, &file_stat);
+ fd = FcDirCacheOpenFile (config, cache_hashed, &file_stat);
- ret = (*callback) (fd, &file_stat, &dir_stat, closure);
+ ret = (*callback) (config, fd, &file_stat, &dir_stat, closure);
-FcCacheTimeValid (FcCache *cache, struct stat *dir_stat)
+FcCacheTimeValid (FcConfig *config, FcCache *cache, struct stat *dir_stat)
{
struct stat dir_static;
if (!dir_stat)
{
{
struct stat dir_static;
if (!dir_stat)
{
- if (FcStat (FcCacheDir (cache), &dir_static) < 0)
+ if (FcStat (config, FcCacheDir (cache), &dir_static) < 0)
return FcFalse;
dir_stat = &dir_static;
}
return FcFalse;
dir_stat = &dir_static;
}
* Map a cache file into memory
*/
static FcCache *
* Map a cache file into memory
*/
static FcCache *
-FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat)
+FcDirCacheMapFd (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat)
{
FcCache *cache;
FcBool allocated = FcFalse;
{
FcCache *cache;
FcBool allocated = FcFalse;
cache = FcCacheFindByStat (fd_stat);
if (cache)
{
cache = FcCacheFindByStat (fd_stat);
if (cache)
{
- if (FcCacheTimeValid (cache, dir_stat))
+ if (FcCacheTimeValid (config, cache, dir_stat))
return cache;
FcDirCacheUnload (cache);
cache = NULL;
return cache;
FcDirCacheUnload (cache);
cache = NULL;
if (cache->magic != FC_CACHE_MAGIC_MMAP ||
cache->version < FC_CACHE_CONTENT_VERSION ||
cache->size != fd_stat->st_size ||
if (cache->magic != FC_CACHE_MAGIC_MMAP ||
cache->version < FC_CACHE_CONTENT_VERSION ||
cache->size != fd_stat->st_size ||
- !FcCacheTimeValid (cache, dir_stat) ||
+ !FcCacheTimeValid (config, cache, dir_stat) ||
!FcCacheInsert (cache, fd_stat))
{
if (allocated)
!FcCacheInsert (cache, fd_stat))
{
if (allocated)
-FcDirCacheMapHelper (int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure)
+FcDirCacheMapHelper (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure)
- FcCache *cache = FcDirCacheMapFd (fd, fd_stat, dir_stat);
+ FcCache *cache = FcDirCacheMapFd (config, fd, fd_stat, dir_stat);
if (!cache)
return FcFalse;
if (!cache)
return FcFalse;
FcCache *
FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat)
FcCache *
FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat)
+{
+ return FcDirCacheLoadFile2 (cache_file, FcConfigGetCurrent (), file_stat);
+}
+
+FcCache *
+FcDirCacheLoadFile2 (const FcChar8 *cache_file, FcConfig *config, struct stat *file_stat)
{
int fd;
FcCache *cache;
{
int fd;
FcCache *cache;
if (!file_stat)
file_stat = &my_file_stat;
if (!file_stat)
file_stat = &my_file_stat;
- fd = FcDirCacheOpenFile (cache_file, file_stat);
+ fd = FcDirCacheOpenFile (config, cache_file, file_stat);
- cache = FcDirCacheMapFd (fd, file_stat, NULL);
+ cache = FcDirCacheMapFd (config, fd, file_stat, NULL);
close (fd);
return cache;
}
close (fd);
return cache;
}
* the magic number and the size field
*/
static FcBool
* the magic number and the size field
*/
static FcBool
-FcDirCacheValidateHelper (int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure)
+FcDirCacheValidateHelper (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure)
{
FcBool ret = FcTrue;
FcCache c;
{
FcBool ret = FcTrue;
FcCache c;
FcStrList *list;
FcChar8 *cache_dir = NULL;
FcChar8 *test_dir;
FcStrList *list;
FcChar8 *cache_dir = NULL;
FcChar8 *test_dir;
+ FcChar8 *full_test_dir;
+ FcBool free_test_dir;
FcCacheSkip *skip;
struct stat cache_stat;
int magic;
FcCacheSkip *skip;
struct stat cache_stat;
int magic;
list = FcStrListCreate (config->cacheDirs);
if (!list)
return FcFalse;
list = FcStrListCreate (config->cacheDirs);
if (!list)
return FcFalse;
+ free_test_dir = FcFalse;
while ((test_dir = FcStrListNext (list))) {
while ((test_dir = FcStrListNext (list))) {
+ if (free_test_dir)
+ FcStrFree (full_test_dir);
+ free_test_dir = FcFalse;
+
+ full_test_dir = FcConfigGetRootPlus (config, test_dir);
+ if (full_test_dir)
+ {
+ free_test_dir = FcTrue;
+ test_dir = full_test_dir;
+ }
+
if (access ((char *) test_dir, W_OK|X_OK) == 0)
{
cache_dir = test_dir;
if (access ((char *) test_dir, W_OK|X_OK) == 0)
{
cache_dir = test_dir;
}
FcStrListDone (list);
if (!cache_dir)
}
FcStrListDone (list);
if (!cache_dir)
FcDirCacheBasename (dir, cache_base);
cache_hashed = FcStrPlus (cache_dir, cache_base);
if (!cache_hashed)
FcDirCacheBasename (dir, cache_base);
cache_hashed = FcStrPlus (cache_dir, cache_base);
if (!cache_hashed)
if (FcDebug () & FC_DBG_CACHE)
printf ("FcDirCacheWriteDir dir \"%s\" file \"%s\"\n",
if (FcDebug () & FC_DBG_CACHE)
printf ("FcDirCacheWriteDir dir \"%s\" file \"%s\"\n",
- if (!FcAtomicLock (atomic))
+ if (!FcAtomicLock2 (config, atomic))
goto bail3;
fd = open((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT | O_BINARY, 0666);
goto bail3;
fd = open((char *)FcAtomicNewFile (atomic), O_RDWR | O_CREAT | O_BINARY, 0666);
*/
if (cache->size < FC_CACHE_MIN_MMAP &&
(skip = FcCacheFindByAddr (cache)) &&
*/
if (cache->size < FC_CACHE_MIN_MMAP &&
(skip = FcCacheFindByAddr (cache)) &&
- FcStat (cache_hashed, &cache_stat))
+ FcStat (config, cache_hashed, &cache_stat))
{
skip->cache_dev = cache_stat.st_dev;
skip->cache_ino = cache_stat.st_ino;
{
skip->cache_dev = cache_stat.st_dev;
skip->cache_ino = cache_stat.st_ino;
FcAtomicDestroy (atomic);
bail1:
FcStrFree (cache_hashed);
FcAtomicDestroy (atomic);
bail1:
FcStrFree (cache_hashed);
+ bail0:
+ if (free_test_dir)
+ FcStrFree (full_test_dir);
if (!config->cacheDirs)
goto bail8;
if (!config->cacheDirs)
goto bail8;
+ config->rootDir = FcStrCopy ((const FcChar8 *) "");
+
config->blanks = 0;
config->substPattern = 0;
config->blanks = 0;
config->substPattern = 0;
-FcConfigNewestFile (FcStrSet *files)
+FcConfigNewestFile (FcConfig *config, FcStrSet *files)
{
FcStrList *list = FcStrListCreate (files);
FcFileTime newest = { 0, FcFalse };
{
FcStrList *list = FcStrListCreate (files);
FcFileTime newest = { 0, FcFalse };
if (list)
{
while ((file = FcStrListNext (list)))
if (list)
{
while ((file = FcStrListNext (list)))
- if (FcStat (file, &statb) == 0)
+ if (FcStat (config, file, &statb) == 0)
if (!newest.set || statb.st_mtime - newest.time > 0)
{
newest.set = FcTrue;
if (!newest.set || statb.st_mtime - newest.time > 0)
{
newest.set = FcTrue;
if (!config)
return FcFalse;
}
if (!config)
return FcFalse;
}
- config_time = FcConfigNewestFile (config->configFiles);
- config_dir_time = FcConfigNewestFile (config->configDirs);
- font_time = FcConfigNewestFile (config->fontDirs);
+ config_time = FcConfigNewestFile (config, config->configFiles);
+ config_dir_time = FcConfigNewestFile (config, config->configDirs);
+ font_time = FcConfigNewestFile (config, config->fontDirs);
if ((config_time.set && config_time.time - config->rescanTime > 0) ||
(config_dir_time.set && (config_dir_time.time - config->rescanTime) > 0) ||
(font_time.set && (font_time.time - config->rescanTime) > 0))
if ((config_time.set && config_time.time - config->rescanTime > 0) ||
(config_dir_time.set && (config_dir_time.time - config->rescanTime) > 0) ||
(font_time.set && (font_time.time - config->rescanTime) > 0))
const FcChar8 *f)
{
FcBool ret;
const FcChar8 *f)
{
FcBool ret;
- FcChar8 *file = FcConfigFilename (f);
+ FcChar8 *file = FcConfigFilename2 (config, f);
if (!file)
return FcFalse;
if (!file)
return FcFalse;
-FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
+FcConfigFileExists (FcConfig *config, const FcChar8 *dir, const FcChar8 *file)
{
FcChar8 *path;
if (!dir)
dir = (const FcChar8 *) "";
{
FcChar8 *path;
if (!dir)
dir = (const FcChar8 *) "";
- path = FcStrPathPlus (dir, file, NULL);
+ path = FcStrPathPlus (FcConfigGetRoot (config), dir, file, NULL);
if (access ((char *) path, R_OK) == 0)
if (access ((char *) path, R_OK) == 0)
+ {
+ FcStrFree (path);
+ return FcStrPathPlus (dir, file, NULL);
+ }
FcStrFree (path);
return 0;
FcStrFree (path);
return 0;
FcChar8 *
FcConfigFilename (const FcChar8 *url)
FcChar8 *
FcConfigFilename (const FcChar8 *url)
+{
+ return FcConfigFilename2 (FcConfigGetCurrent (), url);
+}
+
+FcChar8 *
+FcConfigFilename2 (FcConfig *config, const FcChar8 *url)
{
FcChar8 *file, *dir, **path, **p;
{
FcChar8 *file, *dir, **path, **p;
case '~':
dir = FcConfigHome ();
if (dir)
case '~':
dir = FcConfigHome ();
if (dir)
- file = FcConfigFileExists (dir, url + 1);
+ file = FcConfigFileExists (config, dir, url + 1);
absolute_path:
#endif
case '/':
absolute_path:
#endif
case '/':
- file = FcConfigFileExists (0, url);
+ file = FcConfigFileExists (config, 0, url);
break;
default:
path = FcConfigGetPath ();
break;
default:
path = FcConfigGetPath ();
return 0;
for (p = path; *p; p++)
{
return 0;
for (p = path; *p; p++)
{
- file = FcConfigFileExists (*p, url);
+ file = FcConfigFileExists (config, *p, url);
return FcFalse;
return FcTrue;
}
return FcFalse;
return FcTrue;
}
+
+void
+FcConfigSetRoot (FcConfig *config,
+ const FcChar8 *path)
+{
+ FcStrFree (config->rootDir);
+ config->rootDir = FcStrCopy (path);
+}
+
+const FcChar8 *
+FcConfigGetRoot (FcConfig *config)
+{
+ return config->rootDir;
+}
+
+FcChar8 *
+FcConfigGetRootPlus (FcConfig *config,
+ const FcChar8 *path)
+{
+ /*
+ * Since we have older funcs which do not take a config, it
+ * might be NULL, so handle that as well rather than crash.
+ */
+ if (!config || !config->rootDir)
+ return NULL;
+ return FcStrPathPlus (config->rootDir, path, NULL);
+}
+
#define __fccfg__
#include "fcaliastail.h"
#undef __fccfg__
#define __fccfg__
#include "fcaliastail.h"
#undef __fccfg__
FcBool
FcFileIsDir (const FcChar8 *file)
FcBool
FcFileIsDir (const FcChar8 *file)
+{
+ return FcFileIsDir2 (FcConfigGetCurrent (), file);
+}
+
+FcBool
+FcFileIsDir2 (FcConfig *config, const FcChar8 *file)
- if (FcStat (file, &statb) != 0)
+ if (FcStat (config, file, &statb) != 0)
return FcFalse;
return S_ISDIR(statb.st_mode);
}
return FcFalse;
return S_ISDIR(statb.st_mode);
}
printf ("\tScanning file %s...", file);
fflush (stdout);
}
printf ("\tScanning file %s...", file);
fflush (stdout);
}
- font = FcFreeTypeQuery (file, id, blanks, &count);
+ font = FcFreeTypeQuery2 (config, file, id, blanks, &count);
if (FcDebug () & FC_DBG_SCAN)
printf ("done\n");
if (FcDebug () & FC_DBG_SCAN)
printf ("done\n");
const FcChar8 *file,
FcConfig *config)
{
const FcChar8 *file,
FcConfig *config)
{
- if (FcFileIsDir (file))
+ if (FcFileIsDir2 (config, file))
return FcStrSetAdd (dirs, file);
else
return FcFileScanFontConfig (set, blanks, file, config);
return FcStrSetAdd (dirs, file);
else
return FcFileScanFontConfig (set, blanks, file, config);
FcStrSet *files;
FcChar8 *file;
FcChar8 *base;
FcStrSet *files;
FcChar8 *file;
FcChar8 *base;
+ const FcChar8 *scanDir;
+ FcChar8 *fullDir;
FcBool ret = FcTrue;
int i;
FcBool ret = FcTrue;
int i;
if (FcDebug () & FC_DBG_SCAN)
printf ("\tScanning dir %s\n", dir);
if (FcDebug () & FC_DBG_SCAN)
printf ("\tScanning dir %s\n", dir);
-
- d = opendir ((char *) dir);
+
+ fullDir = FcConfigGetRootPlus (config, dir);
+ if (fullDir)
+ scanDir = fullDir;
+ else
+ scanDir = dir;
+ d = opendir ((char *) scanDir);
+ if (fullDir)
+ FcStrFree (fullDir);
if (!d)
{
/* Don't complain about missing directories */
if (!d)
{
/* Don't complain about missing directories */
if (FcDebug () & FC_DBG_FONTSET)
printf ("cache scan dir %s\n", dir);
if (FcDebug () & FC_DBG_FONTSET)
printf ("cache scan dir %s\n", dir);
- if (FcStat (dir, &dir_stat) < 0)
+ if (FcStat (config, dir, &dir_stat) < 0)
goto bail;
set = FcFontSetCreate();
goto bail;
set = FcFontSetCreate();
-FcFreeTypeQuery(const FcChar8 *file,
- int id,
- FcBlanks *blanks,
- int *count)
+FcFreeTypeQuery (const FcChar8 *file,
+ int id,
+ FcBlanks *blanks,
+ int *count)
+{
+ return FcFreeTypeQuery2 (FcConfigGetCurrent (), file, id, blanks, count);
+}
+
+FcPattern *
+FcFreeTypeQuery2 (FcConfig *config,
+ const FcChar8 *file,
+ int id,
+ FcBlanks *blanks,
+ int *count)
{
FT_Face face;
FT_Library ftLibrary;
FcPattern *pat = NULL;
{
FT_Face face;
FT_Library ftLibrary;
FcPattern *pat = NULL;
+ const FcChar8 *ftFile = file;
+ FcChar8 *fullFile;
if (FT_Init_FreeType (&ftLibrary))
return NULL;
if (FT_Init_FreeType (&ftLibrary))
return NULL;
- if (FT_New_Face (ftLibrary, (char *) file, id, &face))
+ fullFile = FcConfigGetRootPlus (config, file);
+ if (fullFile)
+ ftFile = fullFile;
+
+ if (FT_New_Face (ftLibrary, (char *) ftFile, id, &face))
goto bail;
*count = face->num_faces;
goto bail;
*count = face->num_faces;
FT_Done_Face (face);
bail:
FT_Done_Face (face);
bail:
+ if (fullFile)
+ FcStrFree (fullFile);
FT_Done_FreeType (ftLibrary);
return pat;
}
FT_Done_FreeType (ftLibrary);
return pat;
}
+ /*
+ * The root directory to read config/font/cache/etc... files
+ */
+ FcChar8 *rootDir;
/*
* File names loaded from the configuration -- saved here as the
* cache file must be consulted before the directories are scanned,
/*
* File names loaded from the configuration -- saved here as the
* cache file must be consulted before the directories are scanned,
FcPrivate void
FcDirCacheReference (FcCache *cache, int nref);
FcPrivate void
FcDirCacheReference (FcCache *cache, int nref);
-FcPrivate int
-FcStat (const FcChar8 *file, struct stat *statb);
-
/* fccfg.c */
FcPrivate FcExpr *
/* fccfg.c */
FcPrivate FcExpr *
DIR *d;
struct dirent *e;
FcBool ret = FcTrue;
DIR *d;
struct dirent *e;
FcBool ret = FcTrue;
+ FcChar8 *fullDir;
+ const FcChar8 *scanDir;
FcChar8 *file;
FcChar8 *base;
FcStrSet *files;
FcChar8 *file;
FcChar8 *base;
FcStrSet *files;
- d = opendir ((char *) dir);
+ fullDir = FcConfigGetRootPlus (config, dir);
+ if (fullDir)
+ scanDir = fullDir;
+ else
+ scanDir = dir;
+ d = opendir ((char *) scanDir);
+ if (fullDir)
+ FcStrFree (fullDir);
XML_Parser p;
FcChar8 *filename;
XML_Parser p;
FcChar8 *filename;
+ const FcChar8 *readFile;
+ FcChar8 *fullFile;
int fd;
int len;
FcConfigParse parse;
int fd;
int len;
FcConfigParse parse;
- filename = FcConfigFilename (name);
+ filename = FcConfigFilename2 (config, name);
if (!filename)
goto bail0;
if (!filename)
goto bail0;
- if (FcFileIsDir (filename))
+ if (FcFileIsDir2 (config, filename))
{
FcBool ret = FcConfigParseAndLoadDir (config, name, filename, complain);
FcStrFree (filename);
{
FcBool ret = FcConfigParseAndLoadDir (config, name, filename, complain);
FcStrFree (filename);
if (FcDebug () & FC_DBG_CONFIG)
printf ("\tLoading config file %s\n", filename);
if (FcDebug () & FC_DBG_CONFIG)
printf ("\tLoading config file %s\n", filename);
- fd = open ((char *) filename, O_RDONLY);
+ fullFile = FcConfigGetRootPlus (config, filename);
+ if (fullFile)
+ readFile = fullFile;
+ else
+ readFile = filename;
+ fd = open ((char *) readFile, O_RDONLY);
+ if (fullFile)
+ FcStrFree (fullFile);
if (fd == -1) {
FcStrFree (filename);
goto bail0;
if (fd == -1) {
FcStrFree (filename);
goto bail0;