pkg: add pkg_get_parent_dir() and define $(pcfiledir).

feature/tap-sh
William Pitcock 2012-07-21 14:49:55 -05:00
parent 4d8f2b030f
commit 29ea7ce460
1 changed files with 15 additions and 0 deletions

15
pkg.c
View File

@ -118,6 +118,20 @@ get_pkgconfig_path(void)
return PKG_DEFAULT_PATH;
}
static const char *
pkg_get_parent_dir(pkg_t *pkg)
{
static char buf[PKG_BUFSIZE];
static char filebuf[PKG_BUFSIZE];
char *pathbuf;
strlcpy(filebuf, pkg->filename, sizeof filebuf);
pathbuf = dirname(filebuf);
strlcpy(buf, pathbuf, sizeof buf);
return buf;
}
/*
* pkg_new_from_file(filename, file)
*
@ -131,6 +145,7 @@ pkg_new_from_file(const char *filename, FILE *f)
pkg = calloc(sizeof(pkg_t), 1);
pkg->filename = strdup(filename);
pkg->vars = pkg_tuple_add(pkg->vars, "pcfiledir", pkg_get_parent_dir(pkg));
while (pkg_fgetline(readbuf, PKG_BUFSIZE, f) != NULL)
{