From 67e9c12c5a85e4ee95eb8576d094988d1c765c44 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 29 Oct 2018 17:00:28 -0700 Subject: [PATCH] Fetch FONTCONFIG_SYSROOT in FcConfigCreate This saves the value of FONTCONFIG_SYSROOT in the config instead of having to call getenv every time we need this value. This also uses 'realpath' to construct a canonical path to sysroot, eliminating symlinks and relative path names. Signed-off-by: Keith Packard --- src/fccfg.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/fccfg.c b/src/fccfg.c index a87dfec..11df5ca 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -96,6 +96,20 @@ FcConfigFini (void) FcConfigDestroy (cfg); } +static FcChar8 * +FcConfigRealPath(const FcChar8 *path) +{ + char resolved_name[PATH_MAX+1]; + char *resolved_ret; + + if (!path) + return NULL; + + resolved_ret = realpath((const char *) path, resolved_name); + if (resolved_ret) + path = (FcChar8 *) resolved_ret; + return FcStrCopyFilename(path); +} FcConfig * FcConfigCreate (void) @@ -159,7 +173,7 @@ FcConfigCreate (void) config->expr_pool = NULL; - config->sysRoot = NULL; + config->sysRoot = FcConfigRealPath((const FcChar8 *) getenv("FONTCONFIG_SYSROOT")); config->rulesetList = FcPtrListCreate (FcDestroyAsRuleSet); if (!config->rulesetList) @@ -2462,11 +2476,7 @@ FcConfigGetSysRoot (const FcConfig *config) if (!config) return NULL; } - - if (config->sysRoot) - return config->sysRoot; - - return (FcChar8 *) getenv ("FONTCONFIG_SYSROOT"); + return config->sysRoot; } void @@ -2495,7 +2505,7 @@ FcConfigSetSysRoot (FcConfig *config, if (sysroot) { - s = FcStrCopyFilename (sysroot); + s = FcConfigRealPath(sysroot); if (!s) return; }