forked from ariadne/pkgconf
Make pkg_find() follow the PKG_CONFIG_PATH environmental variable, if available.
parent
3c8bac678d
commit
d0639b3353
4
parse.c
4
parse.c
|
@ -367,13 +367,11 @@ parse_deplist(pkg_t *pkg, const char *depends)
|
||||||
* Parse a .pc file into a pkg_t object structure.
|
* Parse a .pc file into a pkg_t object structure.
|
||||||
*/
|
*/
|
||||||
pkg_t *
|
pkg_t *
|
||||||
parse_file(const char *filename)
|
parse_file(const char *filename, FILE *f)
|
||||||
{
|
{
|
||||||
FILE *f;
|
|
||||||
pkg_t *pkg;
|
pkg_t *pkg;
|
||||||
char readbuf[BUFSIZ];
|
char readbuf[BUFSIZ];
|
||||||
|
|
||||||
f = fopen(filename, "r");
|
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
38
pkg.c
38
pkg.c
|
@ -27,10 +27,46 @@ pkg_t *
|
||||||
pkg_find(const char *name)
|
pkg_find(const char *name)
|
||||||
{
|
{
|
||||||
char locbuf[BUFSIZ];
|
char locbuf[BUFSIZ];
|
||||||
|
char path[BUFSIZ];
|
||||||
|
char *env_path;
|
||||||
|
int count = 0, pcount = 0;
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
snprintf(locbuf, sizeof locbuf, "/usr/lib/pkgconfig/%s.pc", name);
|
snprintf(locbuf, sizeof locbuf, "/usr/lib/pkgconfig/%s.pc", name);
|
||||||
|
if (!(f = fopen(locbuf, "r")))
|
||||||
|
{
|
||||||
|
env_path = getenv("PKG_CONFIG_PATH");
|
||||||
|
if (env_path == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return parse_file(locbuf);
|
while (env_path[count] != '\0')
|
||||||
|
{
|
||||||
|
if (env_path[count] != ':')
|
||||||
|
{
|
||||||
|
path[pcount] = env_path[count];
|
||||||
|
pcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (env_path[count] == ':')
|
||||||
|
{
|
||||||
|
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name);
|
||||||
|
if (f = fopen(locbuf, "r"))
|
||||||
|
return parse_file(locbuf, f);
|
||||||
|
path[0] = '\0';
|
||||||
|
pcount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path[0] != '\0')
|
||||||
|
{
|
||||||
|
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name);
|
||||||
|
f = fopen(locbuf, "r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parse_file(locbuf, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
2
pkg.h
2
pkg.h
|
@ -97,7 +97,7 @@ pkg_t *pkg_verify_dependency(pkg_dependency_t *pkgdep);
|
||||||
const char *pkg_get_comparator(pkg_dependency_t *pkgdep);
|
const char *pkg_get_comparator(pkg_dependency_t *pkgdep);
|
||||||
|
|
||||||
/* parse.c */
|
/* parse.c */
|
||||||
pkg_t *parse_file(const char *path);
|
pkg_t *parse_file(const char *path, FILE *f);
|
||||||
char *tuple_find(pkg_tuple_t *head, const char *key);
|
char *tuple_find(pkg_tuple_t *head, const char *key);
|
||||||
pkg_dependency_t *parse_deplist(pkg_t *pkg, const char *depends);
|
pkg_dependency_t *parse_deplist(pkg_t *pkg, const char *depends);
|
||||||
pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t *tail);
|
pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t *tail);
|
||||||
|
|
Loading…
Reference in New Issue