From b835d74d80468198eba126f515897e2fd97ac908 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 24 Aug 2016 18:51:02 -0500 Subject: [PATCH] fragment: try to apply munging to all path-only fragments (#94) --- libpkgconf/fragment.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/libpkgconf/fragment.c b/libpkgconf/fragment.c index 033c2af..032b006 100644 --- a/libpkgconf/fragment.c +++ b/libpkgconf/fragment.c @@ -70,6 +70,20 @@ pkgconf_fragment_is_special(const char *string) return pkgconf_fragment_is_unmergeable(string); } +static inline void +pkgconf_fragment_munge(char *buf, size_t buflen, const char *source, const char *sysroot_dir) +{ + *buf = '\0'; + + if (sysroot_dir == NULL) + sysroot_dir = pkgconf_tuple_find_global("pc_sysrootdir"); + + if (pkgconf_fragment_should_munge(source, sysroot_dir)) + strlcat(buf, sysroot_dir, buflen); + + strlcat(buf, source, buflen); +} + static inline char * pkgconf_fragment_copy_munged(const char *source, unsigned int flags) { @@ -81,11 +95,7 @@ pkgconf_fragment_copy_munged(const char *source, unsigned int flags) sysroot_dir = pkgconf_tuple_find_global("pc_sysrootdir"); - if (!pkgconf_fragment_should_munge(source, sysroot_dir)) - return strdup(source); - - strlcpy(mungebuf, sysroot_dir, sizeof mungebuf); - strlcat(mungebuf, source, sizeof mungebuf); + pkgconf_fragment_munge(mungebuf, sizeof mungebuf, source, sysroot_dir); return strdup(mungebuf); } @@ -104,19 +114,25 @@ pkgconf_fragment_add(pkgconf_list_t *list, const char *string, unsigned int flag } else { + char mungebuf[PKGCONF_BUFSIZE]; + if (list->tail != NULL && list->tail->data != NULL) { pkgconf_fragment_t *parent = list->tail->data; if (pkgconf_fragment_is_unmergeable(parent->data)) { - size_t len = strlen(parent->data) + strlen(string) + 2; + size_t len; char *newdata; + pkgconf_fragment_munge(mungebuf, sizeof mungebuf, string, NULL); + + len = strlen(parent->data) + strlen(mungebuf) + 2; newdata = malloc(len); + strlcpy(newdata, parent->data, len); strlcat(newdata, " ", len); - strlcat(newdata, string, len); + strlcat(newdata, mungebuf, len); free(parent->data); parent->data = newdata;