Support for <dir prefix="relative"> in "fonts.conf"

This commit is contained in:
Bill Kendrick 2025-02-22 13:06:43 -08:00
parent e04bfc651a
commit 7f1ab23292

View file

@ -30,6 +30,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <locale.h> #include <locale.h>
#include <libgen.h> /* for dirname() */
#include <errno.h> #include <errno.h>
#include <libintl.h> #include <libintl.h>
@ -1294,8 +1296,21 @@ char * * malloc_fontconfig_config_paths(int num_to_malloc, int * num_actually_ma
} }
else if (fontconfig_prefix == FC_PREFIX_RELATIVE) else if (fontconfig_prefix == FC_PREFIX_RELATIVE)
{ {
/* FIXME */ char *fc_cfg_path_copy, *dname;
printf("fonts.conf <dir prefix=\"relative\"> not supported yet!\n");
fc_cfg_path_copy = strdup(fontconfig_config_paths[i]);
dname = dirname(fc_cfg_path_copy);
snprintf(prefix_path, sizeof(prefix_path), "%s/", dname);
free(fc_cfg_path_copy);
/* Per dirname(3):
These functions may return pointers to statically
allocated memory which may be overwritten by
subsequent calls. Alternatively, they may return a
pointer to some part of path, so that the string
referred to by path should not be modified or
freed until the pointer returned by the function
is no longer required.
*/
} }
if (prefix_path[0] != '\0') if (prefix_path[0] != '\0')
@ -1303,8 +1318,8 @@ char * * malloc_fontconfig_config_paths(int num_to_malloc, int * num_actually_ma
char * tmp_str; char * tmp_str;
size_t len; size_t len;
len = strlen(path_str) + strlen(prefix_path); len = strlen(path_str) + strlen(prefix_path) + 1;
tmp_str = (char *) malloc(sizeof(char *) * (len + 1)); tmp_str = (char *) malloc(sizeof(char *) * len);
if (tmp_str != NULL) if (tmp_str != NULL)
{ {
snprintf(tmp_str, len, "%s%s", prefix_path, path_str); snprintf(tmp_str, len, "%s%s", prefix_path, path_str);