From 538317f6c557b4db2ad655de74d7102149227520 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 2 May 2012 18:38:31 +0000 Subject: [PATCH] pkg: add path_split() helper function --- pkg.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/pkg.c b/pkg.c index 82681f6..011cda5 100644 --- a/pkg.c +++ b/pkg.c @@ -30,17 +30,38 @@ #ifdef _WIN32 /* pkg-config uses ';' on win32 as ':' is part of path */ #define PKG_CONFIG_PATH_SEP_S ";" -#define PKG_CONFIG_PATH_SEP ';' +#define PKG_CONFIG_PATH_SEP ':' #else #define PKG_CONFIG_PATH_SEP_S ":" #define PKG_CONFIG_PATH_SEP ':' #endif +static inline int +path_split(char *text, char ***parv) +{ + int count = 0; + char *p; + + if (text == NULL) + return 0; + + *parv = malloc(sizeof (void *)); + + p = text; + while ((*parv[count] = strtok(p, " ")) != NULL) + { + count++, p = NULL; + *parv = realloc(*parv, sizeof (void *) * count); + } + + return count; +} + pkg_t * pkg_find(const char *name) { - char locbuf[BUFSIZ]; - char path[BUFSIZ]; + char locbuf[PKG_CONFIG_PATH_SZ]; + char *path; const char *env_path; int count = 0, pcount = 0; FILE *f; @@ -51,6 +72,7 @@ pkg_find(const char *name) { while (1) { + if (env_path[count] && env_path[count] != PKG_CONFIG_PATH_SEP) { path[pcount] = env_path[count];