From 3707ccd2212f9f1aaca42f8118fc28876af328de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 2 May 2012 15:55:13 +0200 Subject: [PATCH] Fix PKG_CONFIG_PATH precedence, simplify. PKG_CONFIG_PATH paths must take precedence over the default path. Otherwise, we would be unable to override default .pc files. And while I'm at it, simplify the whole code. It is pointless to introduce another buffer and a lot of string mangling for one additional path. --- pkg.c | 65 +++++++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/pkg.c b/pkg.c index fbae31a..82681f6 100644 --- a/pkg.c +++ b/pkg.c @@ -36,28 +36,6 @@ #define PKG_CONFIG_PATH_SEP ':' #endif -static inline const char * -pkg_get_pkgconfig_path(void) -{ - static bool computed = false; - static char path[PKG_CONFIG_PATH_SZ]; - char *env_path; - - if (computed) - return path; - - strlcpy(path, PKG_DEFAULT_PATH, sizeof path); - - env_path = getenv("PKG_CONFIG_PATH"); - if (env_path != NULL) - { - strlcat(path, PKG_CONFIG_PATH_SEP_S, sizeof path); - strlcat(path, env_path, sizeof path); - } - - return path; -} - pkg_t * pkg_find(const char *name) { @@ -67,32 +45,39 @@ pkg_find(const char *name) int count = 0, pcount = 0; FILE *f; - env_path = pkg_get_pkgconfig_path(); - while (1) + /* PKG_CONFIG_PATH has to take precedence */ + env_path = getenv("PKG_CONFIG_PATH"); + if (env_path) { - if (env_path[count] && env_path[count] != PKG_CONFIG_PATH_SEP) + while (1) { - path[pcount] = env_path[count]; - pcount++; - } - else - { - path[pcount] = '\0'; - if (path[0] != '\0') + if (env_path[count] && env_path[count] != PKG_CONFIG_PATH_SEP) { - snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name); - if (f = fopen(locbuf, "r")) - return parse_file(locbuf, f); + path[pcount] = env_path[count]; + pcount++; } - if (env_path[count] == '\0') - break; + else + { + path[pcount] = '\0'; + if (path[0] != '\0') + { + snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name); + if (f = fopen(locbuf, "r")) + return parse_file(locbuf, f); + } + if (env_path[count] == '\0') + break; - pcount = 0; + pcount = 0; + } + + count++; } - - count++; } + snprintf(locbuf, sizeof locbuf, "%s/%s.pc", PKG_DEFAULT_PATH, name); + if (f = fopen(locbuf, "r")) + return parse_file(locbuf, f); return NULL; }