Search XDG Base Directories for personality files

Try $XDG_DATA_HOME/pkgconfig/personality.d and $XDG_DATA_DIRS/pkgconfig/personality.d.
master
Victor Westerhuis 2023-10-31 14:09:55 +01:00 committed by Ariadne Conill
parent d454f62c73
commit 948297b5b8
1 changed files with 38 additions and 6 deletions

View File

@ -241,17 +241,19 @@ personality_warn_func(void *p, const char *fmt, ...)
} }
static pkgconf_cross_personality_t * static pkgconf_cross_personality_t *
load_personality_with_path(const char *path, const char *triplet) load_personality_with_path(const char *path, const char *triplet, bool datadir)
{ {
char pathbuf[PKGCONF_ITEM_SIZE]; char pathbuf[PKGCONF_ITEM_SIZE];
FILE *f; FILE *f;
pkgconf_cross_personality_t *p; pkgconf_cross_personality_t *p;
/* if triplet is null, assume that path is a direct path to the personality file */ /* if triplet is null, assume that path is a direct path to the personality file */
if (triplet != NULL) if (triplet == NULL)
snprintf(pathbuf, sizeof pathbuf, "%s/%s.personality", path, triplet);
else
pkgconf_strlcpy(pathbuf, path, sizeof pathbuf); pkgconf_strlcpy(pathbuf, path, sizeof pathbuf);
else if (datadir)
snprintf(pathbuf, sizeof pathbuf, "%s/pkgconfig/personality.d/%s.personality", path, triplet);
else
snprintf(pathbuf, sizeof pathbuf, "%s/%s.personality", path, triplet);
f = fopen(pathbuf, "r"); f = fopen(pathbuf, "r");
if (f == NULL) if (f == NULL)
@ -281,21 +283,51 @@ pkgconf_cross_personality_find(const char *triplet)
pkgconf_list_t plist = PKGCONF_LIST_INITIALIZER; pkgconf_list_t plist = PKGCONF_LIST_INITIALIZER;
pkgconf_node_t *n; pkgconf_node_t *n;
pkgconf_cross_personality_t *out = NULL; pkgconf_cross_personality_t *out = NULL;
#if ! defined(_WIN32) && ! defined(__HAIKU__)
char pathbuf[PKGCONF_ITEM_SIZE];
const char *envvar;
#endif
out = load_personality_with_path(triplet, NULL); out = load_personality_with_path(triplet, NULL, false);
if (out != NULL) if (out != NULL)
return out; return out;
if (!valid_triplet(triplet)) if (!valid_triplet(triplet))
return NULL; return NULL;
#if ! defined(_WIN32) && ! defined(__HAIKU__)
envvar = getenv("XDG_DATA_HOME");
if (envvar != NULL)
pkgconf_path_add(envvar, &plist, true);
else {
envvar = getenv("HOME");
if (envvar != NULL) {
pkgconf_strlcpy(pathbuf, envvar, sizeof pathbuf);
pkgconf_strlcat(pathbuf, "/.local/share", sizeof pathbuf);
pkgconf_path_add(pathbuf, &plist, true);
}
}
pkgconf_path_build_from_environ("XDG_DATA_DIRS", "/usr/local/share" PKG_CONFIG_PATH_SEP_S "/usr/share", &plist, true);
PKGCONF_FOREACH_LIST_ENTRY(plist.head, n)
{
pkgconf_path_t *pn = n->data;
out = load_personality_with_path(pn->path, triplet, true);
if (out != NULL)
goto finish;
}
pkgconf_path_free(&plist);
#endif
pkgconf_path_split(PERSONALITY_PATH, &plist, true); pkgconf_path_split(PERSONALITY_PATH, &plist, true);
PKGCONF_FOREACH_LIST_ENTRY(plist.head, n) PKGCONF_FOREACH_LIST_ENTRY(plist.head, n)
{ {
pkgconf_path_t *pn = n->data; pkgconf_path_t *pn = n->data;
out = load_personality_with_path(pn->path, triplet); out = load_personality_with_path(pn->path, triplet, false);
if (out != NULL) if (out != NULL)
goto finish; goto finish;
} }