[Fontconfig] how to read config file from current dir (relative to a binary using the lib)

Raimund Steger rs at mytum.de
Mon Aug 27 16:26:06 PDT 2012


Helmut Tessarek wrote:
> [...]
>
> Anyway, I understand that using the ENV var is the only way to manipulate the
> config path. But here's the next problem.
>
> a) fontconfig linked statically
> b) some binary using fontconfig also linked statically
>
> I use setenv in b) to set the FONTCONFIG_PATH variable, but a) ignores it.

Should work:

/* ...
  * no FcInit*() before this point */
char cfgpath[PATH_MAX];
/* need to add "." if relative paths are involved: */
snprintf(cfgpath,PATH_MAX,"%s/cfg:.",dirname(argv[0]));
setenv("FONTCONFIG_PATH",cfgpath,1);
FcInit();

Then, if ./cfg is a valid configuration:

FC_DEBUG=1024 ./the-binary

shows:

         Loading config file ./cfg/fonts.conf
         Scanning config dir ./cfg/conf.d
         Loading config file ././cfg/conf.d/20-fix-globaladvance.conf
         [...]

Note that binaries on Windows have different defaults than UNIX.

Raimund

-- 
Worringer Str 31, Duesseldorf 40211 Germany   home: <rs at mytum.de>
+49-179-2981632 icq 16845346                  work: <rs at interface-ag.de>


More information about the Fontconfig mailing list