2012-05-07 01:18:21 +00:00
|
|
|
/*
|
|
|
|
* tuple.c
|
|
|
|
* management of key->value tuples
|
|
|
|
*
|
2012-07-26 02:09:31 +00:00
|
|
|
* Copyright (c) 2011, 2012 pkgconf authors (see AUTHORS).
|
2012-05-07 01:18:21 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
2012-07-20 19:29:58 +00:00
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
2012-05-07 01:18:21 +00:00
|
|
|
*/
|
|
|
|
|
2017-09-18 04:38:25 +00:00
|
|
|
#include <libpkgconf/stdinc.h>
|
2015-09-06 14:35:08 +00:00
|
|
|
#include <libpkgconf/libpkgconf.h>
|
2012-05-07 01:18:21 +00:00
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* libpkgconf `tuple` module
|
|
|
|
* =========================
|
|
|
|
*
|
|
|
|
* The `tuple` module provides key-value mappings backed by a linked list. The key-value
|
|
|
|
* mapping is mainly used for variable substitution when parsing .pc files.
|
|
|
|
*
|
|
|
|
* There are two sets of mappings: a ``pkgconf_pkg_t`` specific mapping, and a `global` mapping.
|
|
|
|
* The `tuple` module provides convenience wrappers for managing the `global` mapping, which is
|
|
|
|
* attached to a given client object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_tuple_add_global(pkgconf_client_t *client, const char *key, const char *value)
|
|
|
|
*
|
|
|
|
* Defines a global variable, replacing the previous declaration if one was set.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to modify.
|
|
|
|
* :param char* key: The key for the mapping (variable name).
|
|
|
|
* :param char* value: The value for the mapped entry.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2012-05-07 04:10:41 +00:00
|
|
|
void
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_tuple_add_global(pkgconf_client_t *client, const char *key, const char *value)
|
2012-05-07 04:10:41 +00:00
|
|
|
{
|
2022-07-26 17:08:48 +00:00
|
|
|
pkgconf_tuple_add(client, &client->global_vars, key, value, false, 0);
|
2012-05-07 04:10:41 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 19:38:40 +00:00
|
|
|
static pkgconf_tuple_t *
|
|
|
|
lookup_global_tuple(const pkgconf_client_t *client, const char *key)
|
|
|
|
{
|
|
|
|
pkgconf_node_t *node;
|
|
|
|
|
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(client->global_vars.head, node)
|
|
|
|
{
|
|
|
|
pkgconf_tuple_t *tuple = node->data;
|
|
|
|
|
|
|
|
if (!strcmp(tuple->key, key))
|
|
|
|
return tuple;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_tuple_find_global(const pkgconf_client_t *client, const char *key)
|
|
|
|
*
|
|
|
|
* Looks up a global variable.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to access.
|
|
|
|
* :param char* key: The key or variable name to look up.
|
|
|
|
* :return: the contents of the variable or ``NULL``
|
|
|
|
* :rtype: char *
|
|
|
|
*/
|
2012-05-07 04:10:41 +00:00
|
|
|
char *
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_tuple_find_global(const pkgconf_client_t *client, const char *key)
|
2012-05-07 04:10:41 +00:00
|
|
|
{
|
2022-08-16 19:38:40 +00:00
|
|
|
pkgconf_tuple_t *tuple;
|
2012-05-07 04:10:41 +00:00
|
|
|
|
2022-08-16 19:38:40 +00:00
|
|
|
tuple = lookup_global_tuple(client, key);
|
|
|
|
if (tuple == NULL)
|
|
|
|
return NULL;
|
2012-05-07 04:10:41 +00:00
|
|
|
|
2022-08-16 19:38:40 +00:00
|
|
|
return tuple->value;
|
2012-05-07 04:10:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_tuple_free_global(pkgconf_client_t *client)
|
|
|
|
*
|
|
|
|
* Delete all global variables associated with a pkgconf client object.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to modify.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2012-05-07 04:10:41 +00:00
|
|
|
void
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_tuple_free_global(pkgconf_client_t *client)
|
2012-05-07 04:10:41 +00:00
|
|
|
{
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_tuple_free(&client->global_vars);
|
2012-05-07 04:10:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_tuple_define_global(pkgconf_client_t *client, const char *kv)
|
|
|
|
*
|
|
|
|
* Parse and define a global variable.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to modify.
|
|
|
|
* :param char* kv: The variable in the form of ``key=value``.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2012-05-07 04:32:08 +00:00
|
|
|
void
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_tuple_define_global(pkgconf_client_t *client, const char *kv)
|
2012-05-07 04:32:08 +00:00
|
|
|
{
|
|
|
|
char *workbuf = strdup(kv);
|
|
|
|
char *value;
|
2022-08-16 19:38:40 +00:00
|
|
|
pkgconf_tuple_t *tuple;
|
2012-05-07 04:32:08 +00:00
|
|
|
|
|
|
|
value = strchr(workbuf, '=');
|
|
|
|
if (value == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
*value++ = '\0';
|
2022-08-16 19:38:40 +00:00
|
|
|
|
|
|
|
tuple = pkgconf_tuple_add(client, &client->global_vars, workbuf, value, false, 0);
|
|
|
|
if (tuple != NULL)
|
|
|
|
tuple->flags = PKGCONF_PKG_TUPLEF_OVERRIDE;
|
|
|
|
|
2012-05-07 04:32:08 +00:00
|
|
|
out:
|
|
|
|
free(workbuf);
|
|
|
|
}
|
|
|
|
|
2016-12-10 02:58:15 +00:00
|
|
|
static void
|
|
|
|
pkgconf_tuple_find_delete(pkgconf_list_t *list, const char *key)
|
|
|
|
{
|
|
|
|
pkgconf_node_t *node, *next;
|
|
|
|
|
|
|
|
PKGCONF_FOREACH_LIST_ENTRY_SAFE(list->head, next, node)
|
|
|
|
{
|
|
|
|
pkgconf_tuple_t *tuple = node->data;
|
|
|
|
|
|
|
|
if (!strcmp(tuple->key, key))
|
|
|
|
{
|
|
|
|
pkgconf_tuple_free_entry(tuple, list);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 21:12:04 +00:00
|
|
|
static char *
|
|
|
|
dequote(const char *value)
|
|
|
|
{
|
2023-11-05 22:17:02 +00:00
|
|
|
char *buf = calloc(1, (strlen(value) + 1) * 2);
|
2018-06-14 21:12:04 +00:00
|
|
|
char *bptr = buf;
|
|
|
|
const char *i;
|
|
|
|
char quote = 0;
|
|
|
|
|
2019-03-24 03:33:55 +00:00
|
|
|
if (*value == '\'' || *value == '"')
|
|
|
|
quote = *value;
|
|
|
|
|
2018-06-14 21:12:04 +00:00
|
|
|
for (i = value; *i != '\0'; i++)
|
|
|
|
{
|
2019-03-24 03:33:55 +00:00
|
|
|
if (*i == '\\' && quote && *(i + 1) == quote)
|
2018-06-14 21:12:04 +00:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
*bptr++ = *i;
|
|
|
|
}
|
2019-03-24 03:33:55 +00:00
|
|
|
else if (*i != quote)
|
|
|
|
*bptr++ = *i;
|
2018-06-14 21:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2022-07-26 17:08:48 +00:00
|
|
|
static const char *
|
|
|
|
find_sysroot(const pkgconf_client_t *client, pkgconf_list_t *vars)
|
|
|
|
{
|
|
|
|
const char *sysroot_dir;
|
|
|
|
|
|
|
|
sysroot_dir = pkgconf_tuple_find(client, vars, "pc_sysrootdir");
|
|
|
|
if (sysroot_dir == NULL)
|
|
|
|
sysroot_dir = client->sysroot_dir;
|
|
|
|
|
|
|
|
return sysroot_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
should_rewrite_sysroot(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *buf, unsigned int flags)
|
|
|
|
{
|
|
|
|
const char *sysroot_dir;
|
|
|
|
|
|
|
|
if (flags & PKGCONF_PKG_PROPF_UNINSTALLED && !(client->flags & PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
sysroot_dir = find_sysroot(client, vars);
|
|
|
|
if (sysroot_dir == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (*buf != '/')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!strcmp(sysroot_dir, "/"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (strlen(buf) <= strlen(sysroot_dir))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (strstr(buf + strlen(sysroot_dir), sysroot_dir) == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_tuple_t *pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key, const char *value, bool parse)
|
|
|
|
*
|
|
|
|
* Optionally parse and then define a variable.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to access.
|
|
|
|
* :param pkgconf_list_t* list: The variable list to add the new variable to.
|
|
|
|
* :param char* key: The name of the variable being added.
|
|
|
|
* :param char* value: The value of the variable being added.
|
|
|
|
* :param bool parse: Whether or not to parse the value for variable substitution.
|
|
|
|
* :return: a variable object
|
|
|
|
* :rtype: pkgconf_tuple_t *
|
|
|
|
*/
|
2015-09-06 15:41:40 +00:00
|
|
|
pkgconf_tuple_t *
|
2022-07-26 17:08:48 +00:00
|
|
|
pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key, const char *value, bool parse, unsigned int flags)
|
2012-05-07 01:18:21 +00:00
|
|
|
{
|
2018-06-14 21:12:04 +00:00
|
|
|
char *dequote_value;
|
2023-11-05 22:17:02 +00:00
|
|
|
pkgconf_tuple_t *tuple = calloc(1, sizeof(pkgconf_tuple_t));
|
2012-05-07 01:18:21 +00:00
|
|
|
|
2016-12-10 02:58:15 +00:00
|
|
|
pkgconf_tuple_find_delete(list, key);
|
|
|
|
|
2018-06-14 21:12:04 +00:00
|
|
|
dequote_value = dequote(value);
|
|
|
|
|
2012-05-07 01:18:21 +00:00
|
|
|
tuple->key = strdup(key);
|
2015-12-07 23:02:14 +00:00
|
|
|
if (parse)
|
2022-07-26 17:08:48 +00:00
|
|
|
tuple->value = pkgconf_tuple_parse(client, list, dequote_value, flags);
|
2015-12-07 23:02:14 +00:00
|
|
|
else
|
2018-06-14 21:12:04 +00:00
|
|
|
tuple->value = strdup(dequote_value);
|
2012-05-07 01:18:21 +00:00
|
|
|
|
2022-07-26 18:00:22 +00:00
|
|
|
PKGCONF_TRACE(client, "adding tuple to @%p: %s => %s (parsed? %d)", list, key, tuple->value, parse);
|
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_insert(&tuple->iter, tuple, list);
|
2012-05-07 01:18:21 +00:00
|
|
|
|
2018-06-14 21:12:04 +00:00
|
|
|
free(dequote_value);
|
|
|
|
|
2012-05-07 01:18:21 +00:00
|
|
|
return tuple;
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: char *pkgconf_tuple_find(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key)
|
|
|
|
*
|
|
|
|
* Look up a variable in a variable list.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to access.
|
|
|
|
* :param pkgconf_list_t* list: The variable list to search.
|
|
|
|
* :param char* key: The variable name to search for.
|
|
|
|
* :return: the value of the variable or ``NULL``
|
|
|
|
* :rtype: char *
|
|
|
|
*/
|
2012-05-07 01:18:21 +00:00
|
|
|
char *
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_tuple_find(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key)
|
2012-05-07 01:18:21 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *node;
|
2022-08-16 19:38:40 +00:00
|
|
|
pkgconf_tuple_t *global_tuple;
|
|
|
|
|
|
|
|
global_tuple = lookup_global_tuple(client, key);
|
|
|
|
if (global_tuple != NULL && global_tuple->flags & PKGCONF_PKG_TUPLEF_OVERRIDE)
|
|
|
|
return global_tuple->value;
|
2012-05-07 01:18:21 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(list->head, node)
|
2012-05-07 01:18:21 +00:00
|
|
|
{
|
2015-09-06 15:41:40 +00:00
|
|
|
pkgconf_tuple_t *tuple = node->data;
|
2013-03-01 16:45:55 +00:00
|
|
|
|
2014-02-10 23:53:47 +00:00
|
|
|
if (!strcmp(tuple->key, key))
|
2013-03-01 16:45:55 +00:00
|
|
|
return tuple->value;
|
2012-05-07 01:18:21 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 19:38:40 +00:00
|
|
|
if (global_tuple != NULL)
|
|
|
|
return global_tuple->value;
|
|
|
|
|
|
|
|
return NULL;
|
2012-05-07 01:18:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
2022-07-26 17:08:48 +00:00
|
|
|
* .. c:function:: char *pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value, unsigned int flags)
|
2016-12-11 23:28:27 +00:00
|
|
|
*
|
|
|
|
* Parse an expression for variable substitution.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to access.
|
|
|
|
* :param pkgconf_list_t* list: The variable list to search for variables (along side the global variable list).
|
|
|
|
* :param char* value: The ``key=value`` string to parse.
|
2022-07-26 17:08:48 +00:00
|
|
|
* :param uint flags: Any flags to consider while parsing.
|
2016-12-11 23:28:27 +00:00
|
|
|
* :return: the variable data with any variables substituted
|
|
|
|
* :rtype: char *
|
|
|
|
*/
|
2012-05-07 01:18:21 +00:00
|
|
|
char *
|
2022-07-26 17:08:48 +00:00
|
|
|
pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value, unsigned int flags)
|
2012-05-07 01:18:21 +00:00
|
|
|
{
|
2015-09-06 16:29:56 +00:00
|
|
|
char buf[PKGCONF_BUFSIZE];
|
2012-05-07 01:18:21 +00:00
|
|
|
const char *ptr;
|
|
|
|
char *bptr = buf;
|
|
|
|
|
2022-07-26 18:00:22 +00:00
|
|
|
if (!(client->flags & PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES) &&
|
|
|
|
(!(flags & PKGCONF_PKG_PROPF_UNINSTALLED) || (client->flags & PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES)))
|
2021-03-18 12:22:11 +00:00
|
|
|
{
|
|
|
|
if (*value == '/' && client->sysroot_dir != NULL && strncmp(value, client->sysroot_dir, strlen(client->sysroot_dir)))
|
|
|
|
bptr += pkgconf_strlcpy(buf, client->sysroot_dir, sizeof buf);
|
|
|
|
}
|
2016-12-10 03:32:55 +00:00
|
|
|
|
2015-09-06 16:29:56 +00:00
|
|
|
for (ptr = value; *ptr != '\0' && bptr - buf < PKGCONF_BUFSIZE; ptr++)
|
2012-05-07 01:18:21 +00:00
|
|
|
{
|
2014-07-02 04:44:49 +00:00
|
|
|
if (*ptr != '$' || (*ptr == '$' && *(ptr + 1) != '{'))
|
2012-05-07 01:18:21 +00:00
|
|
|
*bptr++ = *ptr;
|
|
|
|
else if (*(ptr + 1) == '{')
|
|
|
|
{
|
2017-10-16 17:56:19 +00:00
|
|
|
char varname[PKGCONF_ITEM_SIZE];
|
2020-05-30 22:25:54 +00:00
|
|
|
char *vend = varname + PKGCONF_ITEM_SIZE - 1;
|
2012-05-07 01:18:21 +00:00
|
|
|
char *vptr = varname;
|
|
|
|
const char *pptr;
|
|
|
|
char *kv, *parsekv;
|
|
|
|
|
|
|
|
*vptr = '\0';
|
|
|
|
|
|
|
|
for (pptr = ptr + 2; *pptr != '\0'; pptr++)
|
|
|
|
{
|
|
|
|
if (*pptr != '}')
|
2020-05-31 01:19:48 +00:00
|
|
|
{
|
2020-05-30 22:25:54 +00:00
|
|
|
if (vptr < vend)
|
|
|
|
*vptr++ = *pptr;
|
2020-05-31 01:19:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*vptr = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-07 01:18:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*vptr = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:00:22 +00:00
|
|
|
PKGCONF_TRACE(client, "lookup tuple %s", varname);
|
|
|
|
|
2023-01-20 22:07:03 +00:00
|
|
|
size_t remain = PKGCONF_BUFSIZE - (bptr - buf);
|
2012-05-07 01:18:21 +00:00
|
|
|
ptr += (pptr - ptr);
|
2016-12-01 21:05:03 +00:00
|
|
|
kv = pkgconf_tuple_find_global(client, varname);
|
2012-05-07 01:18:21 +00:00
|
|
|
if (kv != NULL)
|
|
|
|
{
|
2023-01-20 22:07:03 +00:00
|
|
|
size_t nlen = pkgconf_strlcpy(bptr, kv, remain);
|
|
|
|
if (nlen > remain)
|
|
|
|
{
|
|
|
|
pkgconf_warn(client, "warning: truncating very long variable to 64KB\n");
|
|
|
|
|
|
|
|
bptr = buf + (PKGCONF_BUFSIZE - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bptr += nlen;
|
2015-12-07 23:02:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-01 21:05:03 +00:00
|
|
|
kv = pkgconf_tuple_find(client, vars, varname);
|
2012-05-07 01:18:21 +00:00
|
|
|
|
2015-12-07 23:02:14 +00:00
|
|
|
if (kv != NULL)
|
|
|
|
{
|
2023-01-20 22:07:03 +00:00
|
|
|
size_t nlen;
|
|
|
|
|
2022-07-26 17:08:48 +00:00
|
|
|
parsekv = pkgconf_tuple_parse(client, vars, kv, flags);
|
2023-01-20 22:07:03 +00:00
|
|
|
nlen = pkgconf_strlcpy(bptr, parsekv, remain);
|
|
|
|
free(parsekv);
|
2015-12-07 23:02:14 +00:00
|
|
|
|
2023-01-20 22:07:03 +00:00
|
|
|
if (nlen > remain)
|
|
|
|
{
|
|
|
|
pkgconf_warn(client, "warning: truncating very long variable to 64KB\n");
|
2012-05-07 01:18:21 +00:00
|
|
|
|
2023-01-20 22:07:03 +00:00
|
|
|
bptr = buf + (PKGCONF_BUFSIZE - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bptr += nlen;
|
2015-12-07 23:02:14 +00:00
|
|
|
}
|
2012-05-07 01:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*bptr = '\0';
|
|
|
|
|
2017-07-16 22:35:28 +00:00
|
|
|
/*
|
|
|
|
* Sigh. Somebody actually attempted to use freedesktop.org pkg-config's broken sysroot support,
|
|
|
|
* which was written by somebody who did not understand how sysroots are supposed to work. This
|
|
|
|
* results in an incorrect path being built as the sysroot will be prepended twice, once explicitly,
|
|
|
|
* and once by variable expansion (the pkgconf approach). We could simply make ${pc_sysrootdir} blank,
|
|
|
|
* but sometimes it is necessary to know the explicit sysroot path for other reasons, so we can't really
|
|
|
|
* do that.
|
|
|
|
*
|
|
|
|
* As a result, we check to see if ${pc_sysrootdir} is prepended as a duplicate, and if so, remove the
|
|
|
|
* prepend. This allows us to handle both our approach and the broken freedesktop.org implementation's
|
|
|
|
* approach. Because a path can be shorter than ${pc_sysrootdir}, we do some checks first to ensure it's
|
|
|
|
* safe to skip ahead in the string to scan for our sysroot dir.
|
|
|
|
*
|
|
|
|
* Finally, we call pkgconf_path_relocate() to clean the path of spurious elements.
|
2022-07-26 17:08:48 +00:00
|
|
|
*
|
|
|
|
* New in 1.9: Only attempt to rewrite the sysroot if we are not processing an uninstalled package.
|
2017-07-16 22:35:28 +00:00
|
|
|
*/
|
2022-07-26 17:08:48 +00:00
|
|
|
if (should_rewrite_sysroot(client, vars, buf, flags))
|
2017-07-16 22:35:28 +00:00
|
|
|
{
|
2017-10-16 17:56:19 +00:00
|
|
|
char cleanpath[PKGCONF_ITEM_SIZE];
|
2022-07-26 17:08:48 +00:00
|
|
|
const char *sysroot_dir = find_sysroot(client, vars);
|
2017-07-16 22:35:28 +00:00
|
|
|
|
2022-06-26 19:35:19 +00:00
|
|
|
pkgconf_strlcpy(cleanpath, buf + strlen(sysroot_dir), sizeof cleanpath);
|
2017-07-16 22:35:28 +00:00
|
|
|
pkgconf_path_relocate(cleanpath, sizeof cleanpath);
|
|
|
|
|
|
|
|
return strdup(cleanpath);
|
|
|
|
}
|
|
|
|
|
2012-05-07 01:18:21 +00:00
|
|
|
return strdup(buf);
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_tuple_free_entry(pkgconf_tuple_t *tuple, pkgconf_list_t *list)
|
|
|
|
*
|
|
|
|
* Deletes a variable object, removing it from any variable lists and releasing any memory associated
|
|
|
|
* with it.
|
|
|
|
*
|
|
|
|
* :param pkgconf_tuple_t* tuple: The variable object to release.
|
|
|
|
* :param pkgconf_list_t* list: The variable list the variable object is attached to.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2016-12-10 02:50:33 +00:00
|
|
|
void
|
|
|
|
pkgconf_tuple_free_entry(pkgconf_tuple_t *tuple, pkgconf_list_t *list)
|
|
|
|
{
|
|
|
|
pkgconf_node_delete(&tuple->iter, list);
|
|
|
|
|
|
|
|
free(tuple->key);
|
|
|
|
free(tuple->value);
|
|
|
|
free(tuple);
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:28:27 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_tuple_free(pkgconf_list_t *list)
|
|
|
|
*
|
|
|
|
* Deletes a variable list and any variables attached to it.
|
|
|
|
*
|
|
|
|
* :param pkgconf_list_t* list: The variable list to delete.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2012-05-07 01:18:21 +00:00
|
|
|
void
|
2015-09-06 15:41:40 +00:00
|
|
|
pkgconf_tuple_free(pkgconf_list_t *list)
|
2012-05-07 01:18:21 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *node, *next;
|
2012-05-07 01:18:21 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY_SAFE(list->head, next, node)
|
2016-12-10 02:50:33 +00:00
|
|
|
pkgconf_tuple_free_entry(node->data, list);
|
2022-04-01 21:15:43 +00:00
|
|
|
|
|
|
|
pkgconf_list_zero(list);
|
2012-05-07 01:18:21 +00:00
|
|
|
}
|