From c9dffb8570055c88ec3927359c6f10355792e0ce Mon Sep 17 00:00:00 2001 From: Ignacio Casal Quinteiro Date: Mon, 17 Sep 2018 15:19:18 +0200 Subject: [PATCH 1/3] Fix build on windows with meson --- libpkgconf/config.h.meson | 1 + libpkgconf/personality.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/libpkgconf/config.h.meson b/libpkgconf/config.h.meson index cf9191d..d1236c7 100644 --- a/libpkgconf/config.h.meson +++ b/libpkgconf/config.h.meson @@ -86,3 +86,4 @@ #mesondefine PKG_DEFAULT_PATH #mesondefine SYSTEM_INCLUDEDIR #mesondefine SYSTEM_LIBDIR +#mesondefine PERSONALITY_PATH diff --git a/libpkgconf/personality.c b/libpkgconf/personality.c index 06a0471..a15f8cf 100644 --- a/libpkgconf/personality.c +++ b/libpkgconf/personality.c @@ -17,6 +17,10 @@ #include #include +#ifdef _WIN32 +# define strcasecmp _stricmp +#endif + static bool default_personality_init = false; static pkgconf_cross_personality_t default_personality = { .name = "default", From 9f17da92d2623b5f5e6d96c4d6b85c45f7f79110 Mon Sep 17 00:00:00 2001 From: Ignacio Casal Quinteiro Date: Mon, 17 Sep 2018 15:20:00 +0200 Subject: [PATCH 2/3] On Windows the path prefix should be checked caseless --- libpkgconf/pkg.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index 0c3a692..f723c30 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -188,6 +188,16 @@ determine_prefix(const pkgconf_pkg_t *pkg, char *buf, size_t buflen) return 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) { @@ -198,7 +208,7 @@ pkgconf_pkg_parser_value_set(pkgconf_pkg_t *pkg, const size_t lineno, const char * 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]; From 2c059710291fe95f948d90dba9ec74340bc680e5 Mon Sep 17 00:00:00 2001 From: Ignacio Casal Quinteiro Date: Mon, 17 Sep 2018 15:20:28 +0200 Subject: [PATCH 3/3] Canonicalize paths before using them This fixes a problem where on Windows the prefix would not match if the prefix is generated with backslashes and the rest of the variables use normal slashes --- libpkgconf/pkg.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index f723c30..172a3c8 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -188,6 +188,43 @@ 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) { @@ -201,8 +238,13 @@ is_path_prefix_equal(const char *path1, const char *path2, size_t path2_len) 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. @@ -213,7 +255,7 @@ pkgconf_pkg_parser_value_set(pkgconf_pkg_t *pkg, const size_t lineno, const char 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)) @@ -225,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