Mike Frysinger
2011-Nov-08 05:24 UTC
[Fontconfig] [RFC/PATCH 0/3 v2] fc-cache --root support
The point of these patchsets is to add a --root flag to fc-cache so that people can build up the font cache in a tree other than /. This is useful to people cross-compiling, and for non-root building (chroot won''t work). This ignores the cache file format issue (that''s a later patchset). Mike Frysinger (3): FcStrPathPlus: new helper function FcStat: export for people to use fc-cache: add a --root option fc-cache/fc-cache.c | 59 ++++++++++++++++++++++++++++------------------ fc-cache/fc-cache.sgml | 11 ++++++++- fontconfig/fontconfig.h | 15 ++++++++++++ src/fccache.c | 40 ++++++++++++++++++++++++++++--- src/fccfg.c | 59 +++++++++++++++++++++++------------------------ src/fcdir.c | 13 ++++++++- src/fcfreetype.c | 10 +++++++- src/fcint.h | 2 + src/fcstr.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/fcxml.c | 22 ++++++++++++++++- 10 files changed, 219 insertions(+), 63 deletions(-) -- 1.7.6.1
Mike Frysinger
2011-Nov-08 05:24 UTC
[Fontconfig] [PATCH 1/3] FcStrPathPlus: new helper function
This is like FcStrPlus, except that it takes an arbitrary number of
additional strings to append, and it handles the path separator.
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
fc-cache/fc-cache.c | 12 +----------
fontconfig/fontconfig.h | 3 ++
src/fccfg.c | 31 +--------------------------
src/fcint.h | 2 +
src/fcstr.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 59 insertions(+), 40 deletions(-)
diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
index d265350..98039f7 100644
--- a/fc-cache/fc-cache.c
+++ b/fc-cache/fc-cache.c
@@ -253,24 +253,16 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir,
FcBool verbose)
{
DIR *d;
struct dirent *ent;
- FcChar8 *dir_base;
FcBool ret = FcTrue;
FcBool remove;
FcCache *cache;
struct stat target_stat;
- dir_base = FcStrPlus (dir, (FcChar8 *) "/");
- if (!dir_base)
- {
- fprintf (stderr, "%s: out of memory\n", dir);
- return FcFalse;
- }
if (access ((char *) dir, W_OK) != 0)
{
if (verbose)
printf ("%s: not cleaning %s cache directory\n", dir,
access ((char *) dir, F_OK) == 0 ? "unwritable" :
"non-existent");
- FcStrFree (dir_base);
return FcTrue;
}
if (verbose)
@@ -279,7 +271,6 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool
verbose)
if (!d)
{
perror ((char *) dir);
- FcStrFree (dir_base);
return FcFalse;
}
while ((ent = readdir (d)))
@@ -295,7 +286,7 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool
verbose)
strcmp(ent->d_name + 32, "-" FC_ARCHITECTURE
FC_CACHE_SUFFIX))
continue;
- file_name = FcStrPlus (dir_base, (FcChar8 *) ent->d_name);
+ file_name = FcStrPathPlus (dir, (const FcChar8 *) ent->d_name, NULL);
if (!file_name)
{
fprintf (stderr, "%s: allocation failure\n", dir);
@@ -334,7 +325,6 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool
verbose)
}
closedir (d);
- FcStrFree (dir_base);
return ret;
}
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 23ea222..254acc3 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -860,6 +860,9 @@ FcStrCopyFilename (const FcChar8 *s);
FcPublic FcChar8 *
FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
+
+FcPublic FcChar8 *
+FcStrPathPlus (const FcChar8 *s1, ...);
FcPublic void
FcStrFree (FcChar8 *s);
diff --git a/src/fccfg.c b/src/fccfg.c
index 09c5991..6d55f17 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -1689,38 +1689,11 @@ static FcChar8 *
FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
{
FcChar8 *path;
- int size;
if (!dir)
- dir = (FcChar8 *) "";
+ dir = (const FcChar8 *) "";
- size = strlen ((char *) dir) + 1 + strlen ((char *) file) + 1;
- /*
- * workaround valgrind warning because glibc takes advantage of how it
knows memory is
- * allocated to implement strlen by reading in groups of 4
- */
- size = (size + 3) & ~3;
-
- path = malloc (size);
- if (!path)
- return 0;
-
- strcpy ((char *) path, (const char *) dir);
- /* make sure there''s a single separator */
-#ifdef _WIN32
- if ((!path[0] || (path[strlen((char *) path)-1] != ''/''
&&
- path[strlen((char *) path)-1] != ''\\'')) &&
- !(file[0] == ''/'' ||
- file[0] == ''\\'' ||
- (isalpha (file[0]) && file[1] == '':'' &&
(file[2] == ''/'' || file[2] == ''\\''))))
- strcat ((char *) path, "\\");
-#else
- if ((!path[0] || path[strlen((char *) path)-1] != ''/'')
&& file[0] != ''/'')
- strcat ((char *) path, "/");
-#endif
- strcat ((char *) path, (char *) file);
-
- FcMemAlloc (FC_MEM_STRING, size);
+ path = FcStrPathPlus (dir, file, NULL);
if (access ((char *) path, R_OK) == 0)
return path;
diff --git a/src/fcint.h b/src/fcint.h
index 8179195..0a1a90e 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -56,8 +56,10 @@
#ifdef _WIN32
#define FC_SEARCH_PATH_SEPARATOR '';''
+#define FC_DIR_SEPARATOR ''\\''
#else
#define FC_SEARCH_PATH_SEPARATOR '':''
+#define FC_DIR_SEPARATOR ''/''
#endif
#define FC_DBG_MATCH 1
diff --git a/src/fcstr.c b/src/fcstr.c
index b712e5d..0510c21 100644
--- a/src/fcstr.c
+++ b/src/fcstr.c
@@ -63,6 +63,57 @@ FcStrPlus (const FcChar8 *s1, const FcChar8 *s2)
return s;
}
+FcChar8 *
+FcStrPathPlus (const FcChar8 *s1, ...)
+{
+ va_list ap;
+ const FcChar8 *arg;
+ FcChar8 *s;
+ FcBool addSep;
+ int l;
+ int al;
+
+ va_start (ap, s1);
+ arg = s1;
+ s = NULL;
+ l = 0;
+ do {
+ if (!arg)
+ break;
+ al = strlen ((char *) arg);
+
+ /* make sure there''s a single separator */
+ addSep = FcFalse;
+#ifdef _WIN32
+ if ((!arg[0] || (arg[al - 1] != ''/'' && arg[al - 1]
!= ''\\'')) &&
+ !(file[0] == ''/'' ||
+ file[0] == ''\\'' ||
+ (isalpha (file[0]) && file[1] == '':'' &&
(file[2] == ''/'' || file[2] == ''\\''))))
+ addSep = FcTrue;
+#else
+ if (s && (s[l] != FC_DIR_SEPARATOR && arg[0] !=
FC_DIR_SEPARATOR))
+ addSep = FcTrue;
+#endif
+
+ if (addSep)
+ l += 1;
+ s = realloc (s, l + al + 1);
+ if (!s)
+ return 0;
+ if (addSep)
+ s[l - 1] = FC_DIR_SEPARATOR;
+ memcpy (s + l, arg, al + 1);
+ l += al;
+
+ arg = va_arg (ap, const FcChar8 *);
+ } while (1);
+ va_end (ap);
+
+ if (l)
+ FcMemAlloc (FC_MEM_STRING, l + 1);
+ return s;
+}
+
void
FcStrFree (FcChar8 *s)
{
--
1.7.6.1
Mike Frysinger
2011-Nov-08 05:25 UTC
[Fontconfig] [PATCH 2/3] FcStat: export for people to use
The fc-cache code uses stat() directly, but we already have a FcStat
helper to workaround misc issues, so export it and convert fc-cache
over. This will be even more important when we add --root support.
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
fc-cache/fc-cache.c | 4 ++--
fontconfig/fontconfig.h | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
index 98039f7..64eb22a 100644
--- a/fc-cache/fc-cache.c
+++ b/fc-cache/fc-cache.c
@@ -154,7 +154,7 @@ scanDirs (FcStrList *list, FcConfig *config, FcBool force,
FcBool really_force,
continue;
}
- if (stat ((char *) dir, &statb) == -1)
+ if (FcStat (dir, &statb) == -1)
{
switch (errno) {
case ENOENT:
@@ -304,7 +304,7 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool
verbose)
else
{
target_dir = FcCacheDir (cache);
- if (stat ((char *) target_dir, &target_stat) < 0)
+ if (FcStat (target_dir, &target_stat) < 0)
{
if (verbose)
printf ("%s: %s: missing directory: %s \n",
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 254acc3..cba961d 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -307,6 +307,9 @@ FcBlanksIsMember (FcBlanks *b, FcChar32 ucs4);
/* fccache.c */
+FcPublic int
+FcStat (const FcChar8 *file, struct stat *statb);
+
FcPublic const FcChar8 *
FcCacheDir(const FcCache *c);
--
1.7.6.1
Mike Frysinger
2011-Nov-08 05:25 UTC
[Fontconfig] [PATCH 3/3] fc-cache: add a --root option
We have to add a few new helper options for setting/getting the config
root, and then hooking into the low level dir/file scanners to utilize
these new paths.
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
fc-cache/fc-cache.c | 43 +++++++++++++++++++++++++++++++++----------
fc-cache/fc-cache.sgml | 11 ++++++++++-
fontconfig/fontconfig.h | 9 +++++++++
src/fccache.c | 40 ++++++++++++++++++++++++++++++++++++----
src/fccfg.c | 30 ++++++++++++++++++++++++++++--
src/fcdir.c | 13 +++++++++++--
src/fcfreetype.c | 10 +++++++++-
src/fcxml.c | 22 ++++++++++++++++++++--
8 files changed, 156 insertions(+), 22 deletions(-)
diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
index 64eb22a..b57c731 100644
--- a/fc-cache/fc-cache.c
+++ b/fc-cache/fc-cache.c
@@ -69,6 +69,7 @@
const struct option longopts[] = {
{"force", 0, 0, ''f''},
{"really-force", 0, 0, ''r''},
+ {"root", 1, 0, ''R''},
{"system-only", 0, 0, ''s''},
{"version", 0, 0, ''V''},
{"verbose", 0, 0, ''v''},
@@ -87,10 +88,10 @@ usage (char *program, int error)
{
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",
program);
#else
- 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"
@@ -99,6 +100,7 @@ usage (char *program, int error)
#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");
@@ -106,6 +108,7 @@ usage (char *program, int error)
#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");
@@ -253,25 +256,34 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir,
FcBool verbose)
{
DIR *d;
struct dirent *ent;
+ FcChar8 *fullDir;
+ FcChar8 *checkDir;
FcBool ret = FcTrue;
FcBool remove;
FcCache *cache;
struct stat target_stat;
- if (access ((char *) dir, W_OK) != 0)
+ fullDir = FcConfigGetRootPlus (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");
- return FcTrue;
+ goto done;
}
if (verbose)
printf ("%s: cleaning cache directory\n", dir);
- d = opendir ((char *) dir);
+ d = opendir ((char *) checkDir);
if (!d)
{
perror ((char *) dir);
- return FcFalse;
+ ret = FcFalse;
+ goto done;
}
while ((ent = readdir (d)))
{
@@ -314,17 +326,25 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir,
FcBool verbose)
}
if (remove)
{
- if (unlink ((char *) file_name) < 0)
+ FcChar8 *unlink_file = FcConfigGetRootPlus (file_name);
+ if (!unlink_file)
+ unlink_file = file_name;
+ if (unlink ((char *) unlink_file) < 0)
{
- perror ((char *) file_name);
+ perror ((char *) unlink_file);
ret = FcFalse;
}
+ if (unlink_file != file_name)
+ FcStrFree (unlink_file);
}
FcDirCacheUnload (cache);
FcStrFree (file_name);
}
closedir (d);
+ done:
+ if (fullDir)
+ FcStrFree (fullDir);
return ret;
}
@@ -366,9 +386,9 @@ main (int argc, char **argv)
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)
#else
- while ((c = getopt (argc, argv, "frsVvh")) != -1)
+ while ((c = getopt (argc, argv, "frR:sVvh")) != -1)
#endif
{
switch (c) {
@@ -378,6 +398,9 @@ main (int argc, char **argv)
case ''f'':
force = FcTrue;
break;
+ case ''R'':
+ FcConfigSetRoot (optarg);
+ break;
case ''s'':
systemOnly = FcTrue;
break;
diff --git a/fc-cache/fc-cache.sgml b/fc-cache/fc-cache.sgml
index 3740be7..f5215df 100644
--- a/fc-cache/fc-cache.sgml
+++ b/fc-cache/fc-cache.sgml
@@ -63,9 +63,10 @@ manpage.1: manpage.sgml
<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>--root</option></arg>
<arg><option>--system-only</option></arg>
<arg><option>--verbose</option></arg>
<arg><option>--version</option></arg>
@@ -120,6 +121,14 @@ manpage.1: manpage.sgml
</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>
</term>
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index cba961d..ae7403c 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -412,6 +412,15 @@ FcConfigSubstitute (FcConfig *config,
FcPattern *p,
FcMatchKind kind);
+void
+FcConfigSetRoot (const char *path);
+
+const FcChar8 *
+FcConfigGetRoot (void);
+
+FcChar8 *
+FcConfigGetRootPlus (const FcChar8 *path);
+
/* fccharset.c */
FcPublic FcCharSet*
FcCharSetCreate (void);
diff --git a/src/fccache.c b/src/fccache.c
index c38a705..01ae89f 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -138,7 +138,16 @@ FcStat (const FcChar8 *file, struct stat *statb)
int
FcStat (const FcChar8 *file, struct stat *statb)
{
- return stat ((char *) file, statb);
+ int ret;
+ FcChar8 *fullFile = FcConfigGetRootPlus (file);
+
+ if (fullFile)
+ file = fullFile;
+ ret = stat ((char *) file, statb);
+ if (fullFile)
+ FcStrFree (fullFile);
+
+ return ret;
}
#endif
@@ -207,12 +216,18 @@ static int
FcDirCacheOpenFile (const FcChar8 *cache_file, struct stat *file_stat)
{
int fd;
+ FcChar8 *fullFile;
#ifdef _WIN32
if (FcStat (cache_file, file_stat) < 0)
return -1;
#endif
- fd = open((char *) cache_file, O_RDONLY | O_BINARY);
+ fullFile = FcConfigGetRootPlus (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
@@ -854,6 +869,8 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
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;
@@ -866,7 +883,19 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
list = FcStrListCreate (config->cacheDirs);
if (!list)
return FcFalse;
+ free_test_dir = FcFalse;
while ((test_dir = FcStrListNext (list))) {
+ if (free_test_dir)
+ FcStrFree (full_test_dir);
+ free_test_dir = FcFalse;
+
+ full_test_dir = FcConfigGetRootPlus (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;
@@ -896,12 +925,12 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
}
FcStrListDone (list);
if (!cache_dir)
- return FcFalse;
+ goto bail0;
FcDirCacheBasename (dir, cache_base);
cache_hashed = FcStrPlus (cache_dir, cache_base);
if (!cache_hashed)
- return FcFalse;
+ goto bail0;
if (FcDebug () & FC_DBG_CACHE)
printf ("FcDirCacheWriteDir dir \"%s\" file
\"%s\"\n",
@@ -968,6 +997,9 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
FcAtomicDestroy (atomic);
bail1:
FcStrFree (cache_hashed);
+ bail0:
+ if (free_test_dir)
+ FcStrFree (full_test_dir);
return FcFalse;
}
diff --git a/src/fccfg.c b/src/fccfg.c
index 6d55f17..8274711 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -1693,9 +1693,12 @@ FcConfigFileExists (const FcChar8 *dir, const FcChar8
*file)
if (!dir)
dir = (const FcChar8 *) "";
- path = FcStrPathPlus (dir, file, NULL);
+ path = FcStrPathPlus (FcConfigGetRoot (), dir, file, NULL);
if (access ((char *) path, R_OK) == 0)
- return path;
+ {
+ FcStrFree (path);
+ return FcStrPathPlus (dir, file, NULL);
+ }
FcStrFree (path);
return 0;
@@ -2076,6 +2079,29 @@ FcConfigAcceptFont (FcConfig *config,
return FcFalse;
return FcTrue;
}
+
+static const FcChar8 *_fcRoot = (const FcChar8 *) "";
+
+void
+FcConfigSetRoot (const char *path)
+{
+ _fcRoot = (FcChar8 *) strdup (path);
+}
+
+const FcChar8 *
+FcConfigGetRoot (void)
+{
+ return _fcRoot;
+}
+
+FcChar8 *
+FcConfigGetRootPlus (const FcChar8 *path)
+{
+ if (!_fcRoot[0])
+ return NULL;
+ return FcStrPathPlus (_fcRoot, path, NULL);
+}
+
#define __fccfg__
#include "fcaliastail.h"
#undef __fccfg__
diff --git a/src/fcdir.c b/src/fcdir.c
index d8b094f..0e885a2 100644
--- a/src/fcdir.c
+++ b/src/fcdir.c
@@ -142,6 +142,8 @@ FcDirScanConfig (FcFontSet *set,
FcStrSet *files;
FcChar8 *file;
FcChar8 *base;
+ const FcChar8 *scanDir;
+ FcChar8 *fullDir;
FcBool ret = FcTrue;
int i;
@@ -167,8 +169,15 @@ FcDirScanConfig (FcFontSet *set,
if (FcDebug () & FC_DBG_SCAN)
printf ("\tScanning dir %s\n", dir);
-
- d = opendir ((char *) dir);
+
+ fullDir = FcConfigGetRootPlus (dir);
+ if (fullDir)
+ scanDir = fullDir;
+ else
+ scanDir = dir;
+ d = opendir ((char *) scanDir);
+ if (fullDir)
+ FcStrFree (fullDir);
if (!d)
{
/* Don''t complain about missing directories */
diff --git a/src/fcfreetype.c b/src/fcfreetype.c
index 56ee380..2fc4786 100644
--- a/src/fcfreetype.c
+++ b/src/fcfreetype.c
@@ -1751,11 +1751,17 @@ FcFreeTypeQuery(const FcChar8 *file,
FT_Face face;
FT_Library ftLibrary;
FcPattern *pat = NULL;
+ const FcChar8 *ftFile = file;
+ FcChar8 *fullFile;
if (FT_Init_FreeType (&ftLibrary))
return NULL;
- if (FT_New_Face (ftLibrary, (char *) file, id, &face))
+ fullFile = FcConfigGetRootPlus (file);
+ if (fullFile)
+ ftFile = fullFile;
+
+ if (FT_New_Face (ftLibrary, (char *) ftFile, id, &face))
goto bail;
*count = face->num_faces;
@@ -1764,6 +1770,8 @@ FcFreeTypeQuery(const FcChar8 *file,
FT_Done_Face (face);
bail:
+ if (fullFile)
+ FcStrFree (fullFile);
FT_Done_FreeType (ftLibrary);
return pat;
}
diff --git a/src/fcxml.c b/src/fcxml.c
index ff30b7b..c49373d 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -2603,11 +2603,20 @@ FcConfigParseAndLoadDir (FcConfig *config,
DIR *d;
struct dirent *e;
FcBool ret = FcTrue;
+ FcChar8 *fullDir;
+ const FcChar8 *scanDir;
FcChar8 *file;
FcChar8 *base;
FcStrSet *files;
- d = opendir ((char *) dir);
+ fullDir = FcConfigGetRootPlus (dir);
+ if (fullDir)
+ scanDir = fullDir;
+ else
+ scanDir = dir;
+ d = opendir ((char *) scanDir);
+ if (fullDir)
+ FcStrFree (fullDir);
if (!d)
{
if (complain)
@@ -2685,6 +2694,8 @@ FcConfigParseAndLoad (FcConfig *config,
XML_Parser p;
FcChar8 *filename;
+ const FcChar8 *readFile;
+ FcChar8 *fullFile;
int fd;
int len;
FcConfigParse parse;
@@ -2723,7 +2734,14 @@ FcConfigParseAndLoad (FcConfig *config,
if (FcDebug () & FC_DBG_CONFIG)
printf ("\tLoading config file %s\n", filename);
- fd = open ((char *) filename, O_RDONLY);
+ fullFile = FcConfigGetRootPlus (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;
--
1.7.6.1
Behdad Esfahbod
2011-Nov-08 14:14 UTC
[Fontconfig] [crossdev] [PATCH 3/3] fc-cache: add a --root option
On 11/08/2011 09:31 AM, Mike Frysinger wrote:> On Tuesday 08 November 2011 00:25:01 Mike Frysinger wrote: >> We have to add a few new helper options for setting/getting the config >> root, and then hooking into the low level dir/file scanners to utilize >> these new paths. > > hmm, i''m not familiar with the fontconfig setup. in poking around, it seems > like i should move the root variable into the FcConfig struct rather than > having a dedicated variable for it. that sound about right ? > -mikeSounds right to me.
Mike Frysinger
2011-Nov-08 14:31 UTC
[Fontconfig] [crossdev] [PATCH 3/3] fc-cache: add a --root option
On Tuesday 08 November 2011 00:25:01 Mike Frysinger wrote:> We have to add a few new helper options for setting/getting the config > root, and then hooking into the low level dir/file scanners to utilize > these new paths.hmm, i''m not familiar with the fontconfig setup. in poking around, it seems like i should move the root variable into the FcConfig struct rather than having a dedicated variable for it. that sound about right ? -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: <http://lists.freedesktop.org/archives/fontconfig/attachments/20111108/7d5d45dd/attachment.pgp>