Merge pull request #15 from mgorny/master

win32 registry support + bzero() -> memset()
feature/tap-sh
William Pitcock 2012-05-07 01:34:37 -07:00
commit e16b644165
2 changed files with 73 additions and 1 deletions

View File

@ -44,7 +44,7 @@ pkg_argv_split(const char *src, int *argc, char ***argv)
src_iter = src; src_iter = src;
dst_iter = buf; dst_iter = buf;
bzero(buf, strlen(src) + 1); memset(buf, 0, strlen(src) + 1);
*argv = calloc(sizeof (void *), argv_size); *argv = calloc(sizeof (void *), argv_size);
(*argv)[argc_count] = dst_iter; (*argv)[argc_count] = dst_iter;

72
pkg.c
View File

@ -24,6 +24,11 @@
#include "pkg.h" #include "pkg.h"
#include "bsdstubs.h" #include "bsdstubs.h"
#ifdef _WIN32
# include <windows.h>
# define PKG_CONFIG_REG_KEY "Software\\pkgconfig\\PKG_CONFIG_PATH"
#endif
#define PKG_CONFIG_EXT ".pc" #define PKG_CONFIG_EXT ".pc"
#define PKG_CONFIG_PATH_SZ (65535) #define PKG_CONFIG_PATH_SZ (65535)
@ -206,6 +211,65 @@ pkg_free(pkg_t *pkg)
free(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_t *
pkg_find(const char *name, unsigned int flags) 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: out:
path_free(path, count); path_free(path, count);
return pkg; return pkg;