pkg: add support for treating package names as files

pull/15/head
William Pitcock 2012-05-06 00:12:27 -05:00
parent c0245f54a9
commit a078249a60
1 changed files with 19 additions and 0 deletions

19
pkg.c
View File

@ -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)