Merge branch 'fix-slashes' of nacho/pkgconf into master

feature/tap-sh
kaniini 2018-09-27 02:07:31 +00:00 committed by Gitea
commit ccd2440cde
3 changed files with 60 additions and 3 deletions

View File

@ -86,3 +86,4 @@
#mesondefine PKG_DEFAULT_PATH
#mesondefine SYSTEM_INCLUDEDIR
#mesondefine SYSTEM_LIBDIR
#mesondefine PERSONALITY_PATH

View File

@ -17,6 +17,10 @@
#include <libpkgconf/libpkgconf.h>
#include <libpkgconf/config.h>
#ifdef _WIN32
# define strcasecmp _stricmp
#endif
static bool default_personality_init = false;
static pkgconf_cross_personality_t default_personality = {
.name = "default",

View File

@ -188,22 +188,74 @@ determine_prefix(const pkgconf_pkg_t *pkg, char *buf, size_t buflen)
return buf;
}
static void
remove_additional_separators(char *buf)
{
char *p = buf;
while (*p) {
if (*p == '/') {
char *q;
q = ++p;
while (*q && *q == '/')
q++;
if (p != q)
memmove (p, q, strlen (q) + 1);
} else {
p++;
}
}
}
static void
canonicalize_path(char *buf)
{
#ifdef _WIN32
char *p = buf;
while (*p) {
if (*p == '\\')
*p = '/';
p++;
}
#endif
remove_additional_separators(buf);
}
static bool
is_path_prefix_equal(const char *path1, const char *path2, size_t path2_len)
{
#ifdef _WIN32
return !_strnicmp(path1, path2, path2_len);
#else
return !strncmp(path1, path2, path2_len);
#endif
}
static bool
pkgconf_pkg_parser_value_set(pkgconf_pkg_t *pkg, const size_t lineno, const char *keyword, char *value)
{
char canonicalized_value[PKGCONF_ITEM_SIZE];
(void) lineno;
pkgconf_strlcpy(canonicalized_value, value, sizeof canonicalized_value);
canonicalize_path(canonicalized_value);
/* Some pc files will use absolute paths for all of their directories
* which is broken when redefining the prefix. We try to outsmart the
* file and rewrite any directory that starts with the same prefix.
*/
if (pkg->owner->flags & PKGCONF_PKG_PKGF_REDEFINE_PREFIX && pkg->orig_prefix
&& !strncmp(value, pkg->orig_prefix->value, strlen(pkg->orig_prefix->value)))
&& is_path_prefix_equal(canonicalized_value, pkg->orig_prefix->value, strlen(pkg->orig_prefix->value)))
{
char newvalue[PKGCONF_ITEM_SIZE];
pkgconf_strlcpy(newvalue, pkg->prefix->value, sizeof newvalue);
pkgconf_strlcat(newvalue, value + strlen(pkg->orig_prefix->value), sizeof newvalue);
pkgconf_strlcat(newvalue, canonicalized_value + strlen(pkg->orig_prefix->value), sizeof newvalue);
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, newvalue, false);
}
else if (strcmp(keyword, pkg->owner->prefix_varname) || !(pkg->owner->flags & PKGCONF_PKG_PKGF_REDEFINE_PREFIX))
@ -215,7 +267,7 @@ pkgconf_pkg_parser_value_set(pkgconf_pkg_t *pkg, const size_t lineno, const char
if (relvalue != NULL)
{
pkg->orig_prefix = pkgconf_tuple_add(pkg->owner, &pkg->vars, "orig_prefix", value, true);
pkg->orig_prefix = pkgconf_tuple_add(pkg->owner, &pkg->vars, "orig_prefix", canonicalized_value, true);
pkg->prefix = pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, relvalue, false);
}
else