Merge pull request #1 from mgorny/master

A number of fixes + win32 compat
feature/tap-sh
William Pitcock 2012-05-02 07:49:46 -07:00
commit 281d69eec3
2 changed files with 37 additions and 50 deletions

View File

@ -185,7 +185,7 @@ parse_deplist(pkg_t *pkg, const char *depends)
char *start = buf; char *start = buf;
char *ptr = buf; char *ptr = buf;
char *vstart = NULL; char *vstart = NULL;
char *package, *version; char *package = NULL, *version = NULL;
strlcpy(buf, kvdepends, sizeof buf); strlcpy(buf, kvdepends, sizeof buf);
strlcat(buf, " ", sizeof buf); strlcat(buf, " ", sizeof buf);
@ -373,9 +373,6 @@ parse_file(const char *filename, FILE *f)
pkg_t *pkg; pkg_t *pkg;
char readbuf[BUFSIZ]; char readbuf[BUFSIZ];
if (f == NULL)
return NULL;
pkg = calloc(sizeof(pkg_t), 1); pkg = calloc(sizeof(pkg_t), 1);
pkg->filename = strdup(filename); pkg->filename = strdup(filename);

82
pkg.c
View File

@ -27,27 +27,14 @@
#define PKG_CONFIG_EXT ".pc" #define PKG_CONFIG_EXT ".pc"
#define PKG_CONFIG_PATH_SZ (65535) #define PKG_CONFIG_PATH_SZ (65535)
static inline const char * #ifdef _WIN32
pkg_get_pkgconfig_path(void) /* pkg-config uses ';' on win32 as ':' is part of path */
{ #define PKG_CONFIG_PATH_SEP_S ";"
static bool computed = false; #define PKG_CONFIG_PATH_SEP ';'
static char path[PKG_CONFIG_PATH_SZ]; #else
char *env_path; #define PKG_CONFIG_PATH_SEP_S ":"
#define PKG_CONFIG_PATH_SEP ':'
if (computed) #endif
return path;
strlcpy(path, PKG_DEFAULT_PATH, sizeof path);
env_path = getenv("PKG_CONFIG_PATH");
if (env_path != NULL)
{
strlcat(path, ":", sizeof path);
strlcat(path, env_path, sizeof path);
}
return path;
}
pkg_t * pkg_t *
pkg_find(const char *name) pkg_find(const char *name)
@ -58,37 +45,40 @@ pkg_find(const char *name)
int count = 0, pcount = 0; int count = 0, pcount = 0;
FILE *f; FILE *f;
bzero(path, BUFSIZ); /* PKG_CONFIG_PATH has to take precedence */
env_path = getenv("PKG_CONFIG_PATH");
env_path = pkg_get_pkgconfig_path(); if (env_path)
while (env_path[count] != '\0')
{ {
if (env_path[count] && env_path[count] != ':') while (1)
{ {
path[pcount] = env_path[count]; if (env_path[count] && env_path[count] != PKG_CONFIG_PATH_SEP)
pcount++; {
} path[pcount] = env_path[count];
else pcount++;
{ }
path[pcount] = '\0'; else
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name); {
if (f = fopen(locbuf, "r")) path[pcount] = '\0';
return parse_file(locbuf, f); if (path[0] != '\0')
{
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name);
if (f = fopen(locbuf, "r"))
return parse_file(locbuf, f);
}
if (env_path[count] == '\0')
break;
bzero(path, BUFSIZ); pcount = 0;
pcount = 0; }
}
count++; count++;
}
} }
if (path[0] != '\0') snprintf(locbuf, sizeof locbuf, "%s/%s.pc", PKG_DEFAULT_PATH, name);
{ if (f = fopen(locbuf, "r"))
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name); return parse_file(locbuf, f);
f = fopen(locbuf, "r"); return NULL;
}
return parse_file(locbuf, f);
} }
/* /*