From 524133cd910911a2c5281c4f9bfba6b9eacd182f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 12 May 2012 02:26:55 -0500 Subject: [PATCH] pkg: add support for relative path finding on windows (issue #17) --- pkg.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg.c b/pkg.c index 9bf8552..e8a4905 100644 --- a/pkg.c +++ b/pkg.c @@ -92,11 +92,32 @@ static inline const char * get_pkgconfig_path(void) { const char *env_path; +#ifdef _WIN32 + static char outbuf[MAX_PATH]; + char namebuf[MAX_PATH]; + char *p; +#endif env_path = getenv("PKG_CONFIG_LIBDIR"); if (env_path != NULL) return env_path; +#ifdef _WIN32 + GetModuleFileName(NULL, namebuf, sizeof namebuf); + + p = strrchr(namebuf, '\\'); + if (p == NULL) + p = strrchr(namebuf, '/'); + if (p == NULL) + return PKG_DEFAULT_PATH; + + *p = '\0'; + strlcpy(outbuf, namebuf, sizeof outbuf); + strlcat(outbuf, "/lib/pkgconfig", sizeof outbuf); + + return outbuf; +#endif + return PKG_DEFAULT_PATH; }