Take effect sysroot functionality to the default config file
When loading the default config file with FONTCONFIG_SYSROOT, it fails if no /etc/fonts/fonts.conf is available, even if it is there where is based on sysroot. To address this, FcConfig is required to determine the sysroot. therefore, this change makes FcConfigFilename() deprecated, use FcConfigGetFilename() instead. Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/181
This commit is contained in:
parent
75eadca266
commit
cd51cb241a
|
@ -344,6 +344,15 @@ to be up to date, and used.
|
||||||
@TYPE1@ const FcChar8 * @ARG1@ name
|
@TYPE1@ const FcChar8 * @ARG1@ name
|
||||||
@PURPOSE@ Find a config file
|
@PURPOSE@ Find a config file
|
||||||
@DESC@
|
@DESC@
|
||||||
|
This function is deprecated and is replaced by <function>FcConfigGetFilename</function>.
|
||||||
|
@@
|
||||||
|
|
||||||
|
@RET@ FcChar8 *
|
||||||
|
@FUNC@ FcConfigGetFilename
|
||||||
|
@TYPE1@ FcConfig * @ARG1@ config
|
||||||
|
@TYPE2@ const FcChar8 * @ARG2@ name
|
||||||
|
@PURPOSE@ Find a config file
|
||||||
|
@DESC@
|
||||||
Given the specified external entity name, return the associated filename.
|
Given the specified external entity name, return the associated filename.
|
||||||
This provides applications a way to convert various configuration file
|
This provides applications a way to convert various configuration file
|
||||||
references into filename form.
|
references into filename form.
|
||||||
|
@ -355,6 +364,8 @@ refers to a file in the current users home directory. Otherwise if the name
|
||||||
doesn't start with '/', it refers to a file in the default configuration
|
doesn't start with '/', it refers to a file in the default configuration
|
||||||
directory; the built-in default directory can be overridden with the
|
directory; the built-in default directory can be overridden with the
|
||||||
FONTCONFIG_PATH environment variable.
|
FONTCONFIG_PATH environment variable.
|
||||||
|
</para><para>
|
||||||
|
The result of this function is affected by the FONTCONFIG_SYSROOT environment variable or equivalent functionality.
|
||||||
@@
|
@@
|
||||||
|
|
||||||
@RET@ FcBool
|
@RET@ FcBool
|
||||||
|
|
|
@ -393,6 +393,10 @@ FcConfigHome (void);
|
||||||
FcPublic FcBool
|
FcPublic FcBool
|
||||||
FcConfigEnableHome (FcBool enable);
|
FcConfigEnableHome (FcBool enable);
|
||||||
|
|
||||||
|
FcPublic FcChar8 *
|
||||||
|
FcConfigGetFilename (FcConfig *config,
|
||||||
|
const FcChar8 *url);
|
||||||
|
|
||||||
FcPublic FcChar8 *
|
FcPublic FcChar8 *
|
||||||
FcConfigFilename (const FcChar8 *url);
|
FcConfigFilename (const FcChar8 *url);
|
||||||
|
|
||||||
|
|
67
src/fccfg.c
67
src/fccfg.c
|
@ -686,7 +686,7 @@ FcConfigAddConfigFile (FcConfig *config,
|
||||||
const FcChar8 *f)
|
const FcChar8 *f)
|
||||||
{
|
{
|
||||||
FcBool ret;
|
FcBool ret;
|
||||||
FcChar8 *file = FcConfigFilename (f);
|
FcChar8 *file = FcConfigGetFilename (config, f);
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
|
@ -2284,10 +2284,19 @@ FcConfigEnableHome (FcBool enable)
|
||||||
}
|
}
|
||||||
|
|
||||||
FcChar8 *
|
FcChar8 *
|
||||||
FcConfigFilename (const FcChar8 *url)
|
FcConfigGetFilename (FcConfig *config,
|
||||||
|
const FcChar8 *url)
|
||||||
{
|
{
|
||||||
FcChar8 *file, *dir, **path, **p;
|
FcChar8 *file, *dir, **path, **p;
|
||||||
|
const FcChar8 *sysroot;
|
||||||
|
|
||||||
|
if (!config)
|
||||||
|
{
|
||||||
|
config = FcConfigGetCurrent ();
|
||||||
|
if (!config)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
sysroot = FcConfigGetSysRoot (config);
|
||||||
if (!url || !*url)
|
if (!url || !*url)
|
||||||
{
|
{
|
||||||
url = (FcChar8 *) getenv ("FONTCONFIG_FILE");
|
url = (FcChar8 *) getenv ("FONTCONFIG_FILE");
|
||||||
|
@ -2297,13 +2306,23 @@ FcConfigFilename (const FcChar8 *url)
|
||||||
file = 0;
|
file = 0;
|
||||||
|
|
||||||
if (FcStrIsAbsoluteFilename(url))
|
if (FcStrIsAbsoluteFilename(url))
|
||||||
return FcConfigFileExists (0, url);
|
return FcConfigFileExists (sysroot, url);
|
||||||
|
|
||||||
if (*url == '~')
|
if (*url == '~')
|
||||||
{
|
{
|
||||||
dir = FcConfigHome ();
|
dir = FcConfigHome ();
|
||||||
if (dir)
|
if (dir)
|
||||||
file = FcConfigFileExists (dir, url + 1);
|
{
|
||||||
|
FcChar8 *s;
|
||||||
|
|
||||||
|
if (sysroot)
|
||||||
|
s = FcStrBuildFilename (sysroot, dir, NULL);
|
||||||
|
else
|
||||||
|
s = dir;
|
||||||
|
file = FcConfigFileExists (s, url + 1);
|
||||||
|
if (sysroot)
|
||||||
|
FcStrFree (s);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
file = 0;
|
file = 0;
|
||||||
}
|
}
|
||||||
|
@ -2314,7 +2333,15 @@ FcConfigFilename (const FcChar8 *url)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (p = path; *p; p++)
|
for (p = path; *p; p++)
|
||||||
{
|
{
|
||||||
file = FcConfigFileExists (*p, url);
|
FcChar8 *s;
|
||||||
|
|
||||||
|
if (sysroot)
|
||||||
|
s = FcStrBuildFilename (sysroot, *p, NULL);
|
||||||
|
else
|
||||||
|
s = *p;
|
||||||
|
file = FcConfigFileExists (s, url);
|
||||||
|
if (sysroot)
|
||||||
|
FcStrFree (s);
|
||||||
if (file)
|
if (file)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2323,33 +2350,31 @@ FcConfigFilename (const FcChar8 *url)
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FcChar8 *
|
||||||
|
FcConfigFilename (const FcChar8 *url)
|
||||||
|
{
|
||||||
|
return FcConfigGetFilename (NULL, url);
|
||||||
|
}
|
||||||
|
|
||||||
FcChar8 *
|
FcChar8 *
|
||||||
FcConfigRealFilename (FcConfig *config,
|
FcConfigRealFilename (FcConfig *config,
|
||||||
const FcChar8 *url)
|
const FcChar8 *url)
|
||||||
{
|
{
|
||||||
const FcChar8 *sysroot = FcConfigGetSysRoot (config);
|
FcChar8 *n = FcConfigGetFilename (config, url);
|
||||||
FcChar8 *n = FcConfigFilename (url);
|
|
||||||
FcChar8 *nn = NULL;
|
|
||||||
|
|
||||||
if (n)
|
if (n)
|
||||||
{
|
{
|
||||||
FcChar8 buf[FC_PATH_MAX];
|
FcChar8 buf[FC_PATH_MAX];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
if (sysroot)
|
if ((len = FcReadLink (n, buf, sizeof (buf) - 1)) != -1)
|
||||||
nn = FcStrBuildFilename (sysroot, n, NULL);
|
|
||||||
else
|
|
||||||
nn = FcStrdup (n);
|
|
||||||
FcStrFree (n);
|
|
||||||
|
|
||||||
if ((len = FcReadLink (nn, buf, sizeof (buf) - 1)) != -1)
|
|
||||||
{
|
{
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
|
|
||||||
if (!FcStrIsAbsoluteFilename (buf))
|
if (!FcStrIsAbsoluteFilename (buf))
|
||||||
{
|
{
|
||||||
FcChar8 *dirname = FcStrDirname (nn);
|
FcChar8 *dirname = FcStrDirname (n);
|
||||||
FcStrFree (nn);
|
FcStrFree (n);
|
||||||
if (!dirname)
|
if (!dirname)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -2358,18 +2383,18 @@ FcConfigRealFilename (FcConfig *config,
|
||||||
if (!path)
|
if (!path)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
nn = FcStrCanonFilename (path);
|
n = FcStrCanonFilename (path);
|
||||||
FcStrFree (path);
|
FcStrFree (path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FcStrFree (nn);
|
FcStrFree (n);
|
||||||
nn = FcStrdup (buf);
|
n = FcStrdup (buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nn;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
24
src/fcxml.c
24
src/fcxml.c
|
@ -2541,7 +2541,7 @@ FcParseInclude (FcConfigParse *parse)
|
||||||
FcChar8 *filename;
|
FcChar8 *filename;
|
||||||
static FcBool warn_conf = FcFalse, warn_confd = FcFalse;
|
static FcBool warn_conf = FcFalse, warn_confd = FcFalse;
|
||||||
|
|
||||||
filename = FcConfigFilename(s);
|
filename = FcConfigGetFilename(parse->config, s);
|
||||||
if (deprecated == FcTrue &&
|
if (deprecated == FcTrue &&
|
||||||
filename != NULL &&
|
filename != NULL &&
|
||||||
userdir != NULL &&
|
userdir != NULL &&
|
||||||
|
@ -3532,7 +3532,9 @@ _FcConfigParse (FcConfig *config,
|
||||||
FcStrBuf sbuf;
|
FcStrBuf sbuf;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
FcBool ret = FcFalse, complain_again = complain;
|
FcBool ret = FcFalse, complain_again = complain;
|
||||||
|
FcStrBuf reason;
|
||||||
|
|
||||||
|
FcStrBufInit (&reason, NULL, 0);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (!pGetSystemWindowsDirectory)
|
if (!pGetSystemWindowsDirectory)
|
||||||
{
|
{
|
||||||
|
@ -3549,12 +3551,20 @@ _FcConfigParse (FcConfig *config,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
filename = FcConfigFilename (name);
|
filename = FcConfigGetFilename (config, name);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
|
{
|
||||||
|
FcStrBufString (&reason, (FcChar8 *)"No such file: ");
|
||||||
|
FcStrBufString (&reason, name ? name : (FcChar8 *)"(null)");
|
||||||
goto bail0;
|
goto bail0;
|
||||||
|
}
|
||||||
realfilename = FcConfigRealFilename (config, name);
|
realfilename = FcConfigRealFilename (config, name);
|
||||||
if (!realfilename)
|
if (!realfilename)
|
||||||
|
{
|
||||||
|
FcStrBufString (&reason, (FcChar8 *)"No such realfile: ");
|
||||||
|
FcStrBufString (&reason, name ? name : (FcChar8 *)"(null)");
|
||||||
goto bail0;
|
goto bail0;
|
||||||
|
}
|
||||||
if (FcStrSetMember (config->availConfigFiles, realfilename))
|
if (FcStrSetMember (config->availConfigFiles, realfilename))
|
||||||
{
|
{
|
||||||
FcStrFree (filename);
|
FcStrFree (filename);
|
||||||
|
@ -3582,7 +3592,11 @@ _FcConfigParse (FcConfig *config,
|
||||||
|
|
||||||
fd = FcOpen ((char *) realfilename, O_RDONLY);
|
fd = FcOpen ((char *) realfilename, O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
FcStrBufString (&reason, (FcChar8 *)"Unable to open ");
|
||||||
|
FcStrBufString (&reason, realfilename);
|
||||||
goto bail1;
|
goto bail1;
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
len = read (fd, buf, BUFSIZ);
|
len = read (fd, buf, BUFSIZ);
|
||||||
|
@ -3623,11 +3637,13 @@ bail0:
|
||||||
if (!ret && complain_again)
|
if (!ret && complain_again)
|
||||||
{
|
{
|
||||||
if (name)
|
if (name)
|
||||||
FcConfigMessage (0, FcSevereError, "Cannot %s config file \"%s\"", load ? "load" : "scan", name);
|
FcConfigMessage (0, FcSevereError, "Cannot %s config file \"%s\": %s", load ? "load" : "scan", name, FcStrBufDoneStatic (&reason));
|
||||||
else
|
else
|
||||||
FcConfigMessage (0, FcSevereError, "Cannot %s default config file", load ? "load" : "scan");
|
FcConfigMessage (0, FcSevereError, "Cannot %s default config file: %s", load ? "load" : "scan", FcStrBufDoneStatic (&reason));
|
||||||
|
FcStrBufDestroy (&reason);
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
}
|
}
|
||||||
|
FcStrBufDestroy (&reason);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue