From 0ac7978ee233b28b99c3696025b8d946a42ed982 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 26 Jul 2012 00:01:40 -0500 Subject: [PATCH] pkg: bug fixes --- pkg.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg.c b/pkg.c index 67f3c1c..9c45301 100644 --- a/pkg.c +++ b/pkg.c @@ -286,16 +286,24 @@ pkg_scan_dir(const char *path, pkg_iteration_func_t func) for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir)) { + static char filebuf[PKG_BUFSIZE]; pkg_t *pkg; FILE *f; - f = fopen(dirent->d_name, "r"); + strlcpy(filebuf, path, sizeof filebuf); + strlcat(filebuf, "/", sizeof filebuf); + strlcat(filebuf, dirent->d_name, sizeof filebuf); + + f = fopen(filebuf, "r"); if (f == NULL) continue; - pkg = pkg_new_from_file(dirent->d_name, f); + pkg = pkg_new_from_file(filebuf, f); if (pkg != NULL) + { func(pkg); + pkg_free(pkg); + } } closedir(dir); @@ -327,11 +335,11 @@ pkg_scan_all(pkg_iteration_func_t func) path = getenv("PKG_CONFIG_PATH"); if (path) { - pkg_scan_dir(path, func); + pkg_scan(path, func); return; } - pkg_scan_dir(get_pkgconfig_path(), func); + pkg_scan(get_pkgconfig_path(), func); } #ifdef _WIN32