diff --git a/argvsplit.c b/argvsplit.c index d7044c2..f88411d 100644 --- a/argvsplit.c +++ b/argvsplit.c @@ -44,7 +44,7 @@ pkg_argv_split(const char *src, int *argc, char ***argv) src_iter = src; dst_iter = buf; - bzero(buf, strlen(src) + 1); + memset(buf, 0, strlen(src) + 1); *argv = calloc(sizeof (void *), argv_size); (*argv)[argc_count] = dst_iter; diff --git a/main.c b/main.c index 5ac7a3c..405c9a3 100644 --- a/main.c +++ b/main.c @@ -60,8 +60,6 @@ static int want_keep_system_libs = 0; static int maximum_traverse_depth = -1; static char *required_pkgconfig_version = NULL; -static char *required_exact_module_version = NULL; -static char *required_max_module_version = NULL; static char *required_module_version = NULL; static char *want_variable = NULL; @@ -444,8 +442,6 @@ usage(void) printf("\nchecking specific pkg-config database entries:\n\n"); printf(" --atleast-version require a specific version of a module\n"); - printf(" --exact-version require an exact version of a module\n"); - printf(" --max-version require a maximum version of a module\n"); printf(" --exists check whether or not a module exists\n"); printf(" --uninstalled check whether or not an uninstalled module will be used\n"); printf(" --no-uninstalled never use uninstalled modules when satisfying dependencies\n"); @@ -512,8 +508,6 @@ main(int argc, char *argv[]) { "keep-system-cflags", no_argument, &want_keep_system_cflags, 26, }, { "keep-system-libs", no_argument, &want_keep_system_libs, 26, }, { "define-variable", required_argument, NULL, 27, }, - { "exact-version", required_argument, NULL, 28, }, - { "max-version", required_argument, NULL, 29, }, { NULL, 0, NULL, 0 } }; @@ -536,12 +530,6 @@ main(int argc, char *argv[]) case 27: pkg_tuple_define_global(optarg); break; - case 28: - required_exact_module_version = optarg; - break; - case 29: - required_max_module_version = optarg; - break; default: break; } @@ -601,44 +589,6 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - if (required_exact_module_version != NULL) - { - pkg_t *pkg; - const char *package; - - package = argv[optind]; - if (package == NULL) - return EXIT_SUCCESS; - - pkg = pkg_find(package, global_traverse_flags); - if (pkg == NULL) - return EXIT_FAILURE; - - if (pkg_compare_version(pkg->version, required_exact_module_version) == 0) - return EXIT_SUCCESS; - - return EXIT_FAILURE; - } - - if (required_max_module_version != NULL) - { - pkg_t *pkg; - const char *package; - - package = argv[optind]; - if (package == NULL) - return EXIT_SUCCESS; - - pkg = pkg_find(package, global_traverse_flags); - if (pkg == NULL) - return EXIT_FAILURE; - - if (pkg_compare_version(pkg->version, required_max_module_version) <= 0) - return EXIT_SUCCESS; - - return EXIT_FAILURE; - } - while (1) { const char *package = argv[optind]; diff --git a/pkg.c b/pkg.c index 5dda1d6..fedaf90 100644 --- a/pkg.c +++ b/pkg.c @@ -24,6 +24,11 @@ #include "pkg.h" #include "bsdstubs.h" +#ifdef _WIN32 +# include +# define PKG_CONFIG_REG_KEY "Software\\pkgconfig\\PKG_CONFIG_PATH" +#endif + #define PKG_CONFIG_EXT ".pc" #define PKG_CONFIG_PATH_SZ (65535) @@ -206,6 +211,65 @@ pkg_free(pkg_t *pkg) free(pkg); } +#ifdef _WIN32 +pkg_t * +pkg_find_in_registry_key(HKEY hkey, const char *name, unsigned int flags) +{ + pkg_t *pkg = NULL; + char locbuf[PKG_CONFIG_PATH_SZ]; + char uninst_locbuf[PKG_CONFIG_PATH_SZ]; + + HKEY key; + int i = 0; + + char buf[16384]; /* per registry limits */ + DWORD bufsize = sizeof buf; + if (RegOpenKeyEx(hkey, PKG_CONFIG_REG_KEY, + 0, KEY_READ, &key) != ERROR_SUCCESS) + return NULL; + + while (RegEnumValue(key, i++, buf, &bufsize, NULL, NULL, NULL, NULL) + == ERROR_SUCCESS) + { + BYTE pathbuf[PKG_CONFIG_PATH_SZ]; + DWORD type; + DWORD pathbuflen = sizeof pathbuf; + + if (RegQueryValueEx(key, buf, NULL, &type, pathbuf, &pathbuflen) + == ERROR_SUCCESS && type == REG_SZ) + { + FILE *f; + /* XXX: support REG_EXPAND_SZ? */ + + snprintf(locbuf, sizeof locbuf, "%s/%s" PKG_CONFIG_EXT, + pathbuf, name); + snprintf(uninst_locbuf, sizeof uninst_locbuf, + "%s/%s-uninstalled" PKG_CONFIG_EXT, pathbuf, name); + + if (!(flags & PKGF_NO_UNINSTALLED) + && (f = fopen(uninst_locbuf, "r")) != NULL) + { + pkg = pkg_new_from_file(locbuf, f); + pkg->uninstalled = true; + + break; + } + + if ((f = fopen(locbuf, "r")) != NULL) + { + pkg = pkg_new_from_file(locbuf, f); + break; + } + } + + bufsize = sizeof buf; + } + + RegCloseKey(key); + return pkg; +} +#endif + pkg_t * pkg_find(const char *name, unsigned int flags) { @@ -280,6 +344,14 @@ pkg_find(const char *name, unsigned int flags) } } +#ifdef _WIN32 + /* support getting PKG_CONFIG_PATH from registry */ + + pkg = pkg_find_in_registry_key(HKEY_CURRENT_USER, name, flags); + if (!pkg) + pkg = pkg_find_in_registry_key(HKEY_LOCAL_MACHINE, name, flags); +#endif + out: path_free(path, count); return pkg;