diff --git a/doc/libpkgconf-client.rst b/doc/libpkgconf-client.rst index 7556b9d..695365b 100644 --- a/doc/libpkgconf-client.rst +++ b/doc/libpkgconf-client.rst @@ -112,3 +112,21 @@ thread boundaries. :param pkgconf_client_t* client: The client object to set the resolver-specific flags on. :return: nothing + +.. c:function:: const char *pkgconf_client_get_prefix_varname(const pkgconf_client_t *client) + + Retrieves the name of the variable that should contain a module's prefix. + In some cases, it is necessary to override this variable to allow proper path relocation. + + :param pkgconf_client_t* client: The client object to retrieve the prefix variable name from. + :return: the prefix variable name as a string + :rtype: const char * + +.. c:function:: void pkgconf_client_set_prefix_varname(pkgconf_client_t *client, const char *prefix_varname) + + Sets the name of the variable that should contain a module's prefix. + If the variable name is ``NULL``, then the default variable name (``prefix``) is used. + + :param pkgconf_client_t* client: The client object to set the prefix variable name on. + :param char* prefix_varname: The prefix variable name to set. + :return: nothing diff --git a/libpkgconf/client.c b/libpkgconf/client.c index 2ab4e61..a448065 100644 --- a/libpkgconf/client.c +++ b/libpkgconf/client.c @@ -50,6 +50,7 @@ pkgconf_client_init(pkgconf_client_t *client, pkgconf_error_handler_func_t error pkgconf_client_set_sysroot_dir(client, NULL); pkgconf_client_set_buildroot_dir(client, NULL); + pkgconf_client_set_prefix_varname(client, NULL); if (client->error_handler == NULL) client->error_handler = pkgconf_default_error_handler; @@ -98,6 +99,9 @@ pkgconf_client_new(pkgconf_error_handler_func_t error_handler, void *error_handl void pkgconf_client_deinit(pkgconf_client_t *client) { + if (client->prefix_varname != NULL) + free(client->prefix_varname); + if (client->sysroot_dir != NULL) free(client->sysroot_dir); @@ -290,3 +294,45 @@ pkgconf_client_set_flags(pkgconf_client_t *client, unsigned int flags) { client->flags = flags; } + +/* + * !doc + * + * .. c:function:: const char *pkgconf_client_get_prefix_varname(const pkgconf_client_t *client) + * + * Retrieves the name of the variable that should contain a module's prefix. + * In some cases, it is necessary to override this variable to allow proper path relocation. + * + * :param pkgconf_client_t* client: The client object to retrieve the prefix variable name from. + * :return: the prefix variable name as a string + * :rtype: const char * + */ +const char * +pkgconf_client_get_prefix_varname(const pkgconf_client_t *client) +{ + return client->prefix_varname; +} + +/* + * !doc + * + * .. c:function:: void pkgconf_client_set_prefix_varname(pkgconf_client_t *client, const char *prefix_varname) + * + * Sets the name of the variable that should contain a module's prefix. + * If the variable name is ``NULL``, then the default variable name (``prefix``) is used. + * + * :param pkgconf_client_t* client: The client object to set the prefix variable name on. + * :param char* prefix_varname: The prefix variable name to set. + * :return: nothing + */ +void +pkgconf_client_set_prefix_varname(pkgconf_client_t *client, const char *prefix_varname) +{ + if (prefix_varname == NULL) + prefix_varname = "prefix"; + + if (client->prefix_varname != NULL) + free(client->prefix_varname); + + client->prefix_varname = strdup(prefix_varname); +} diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index cbc42a7..22dfb0f 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -152,6 +152,8 @@ struct pkgconf_client_ { char *buildroot_dir; unsigned int flags; + + char *prefix_varname; }; /* client.c */ @@ -165,6 +167,8 @@ const char *pkgconf_client_get_buildroot_dir(const pkgconf_client_t *client); void pkgconf_client_set_buildroot_dir(pkgconf_client_t *client, const char *buildroot_dir); unsigned int pkgconf_client_get_flags(const pkgconf_client_t *client); void pkgconf_client_set_flags(pkgconf_client_t *client, unsigned int flags); +const char *pkgconf_client_get_prefix_varname(const pkgconf_client_t *client); +void pkgconf_client_set_prefix_varname(pkgconf_client_t *client, const char *prefix_varname); #define PKGCONF_IS_MODULE_SEPARATOR(c) ((c) == ',' || isspace ((unsigned int)(c))) #define PKGCONF_IS_OPERATOR_CHAR(c) ((c) == '<' || (c) == '>' || (c) == '!' || (c) == '=')