From a078249a60521d0b30ab4f513f7424b31d44eef4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 6 May 2012 00:12:27 -0500 Subject: [PATCH] pkg: add support for treating package names as files --- pkg.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg.c b/pkg.c index bbcbb72..22cbbf1 100644 --- a/pkg.c +++ b/pkg.c @@ -58,6 +58,18 @@ path_split(const char *text, char ***parv) return count; } +static inline bool +str_has_suffix(const char *str, const char *suffix) +{ + size_t str_len = strlen(str); + size_t suf_len = strlen(suffix); + + if (str_len < suf_len) + return false; + + return !strncasecmp(str + str_len - suf_len, suffix, suf_len); +} + pkg_t * pkg_find(const char *name, unsigned int flags) { @@ -68,6 +80,13 @@ pkg_find(const char *name, unsigned int flags) const char *env_path; FILE *f; + /* name might actually be a filename. */ + if (str_has_suffix(name, PKG_CONFIG_EXT)) + { + if ((f = fopen(name, "r")) != NULL) + return parse_file(name, f); + } + /* PKG_CONFIG_PATH has to take precedence */ env_path = getenv("PKG_CONFIG_PATH"); if (env_path)