aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2014-07-07 15:27:19 +0200
committerMartin Willi <martin@revosec.ch>2014-07-07 16:14:17 +0200
commitc1490c649a94b09a66b154af781ff0aea20ffa44 (patch)
tree089ad94ac740bc1312ff5a07203022bd32c6e21b
parent44870e531309de01bf1eb92976d5046ab6526fb0 (diff)
downloadstrongswan-c1490c649a94b09a66b154af781ff0aea20ffa44.tar.bz2
strongswan-c1490c649a94b09a66b154af781ff0aea20ffa44.tar.xz
enumerator: Enumerate glob(3) matches using gl_pathc
While glob should return a NULL terminated gl_pathv when having no matches, at least on OS X this is not true when using GLOB_DOOFFS. Rely on the number of matches returned in gl_pathc, which seems to be more reliable in error cases.
-rw-r--r--src/libstrongswan/collections/enumerator.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/libstrongswan/collections/enumerator.c b/src/libstrongswan/collections/enumerator.c
index 0c97f796f..fa277e7c8 100644
--- a/src/libstrongswan/collections/enumerator.c
+++ b/src/libstrongswan/collections/enumerator.c
@@ -171,8 +171,8 @@ typedef struct {
enumerator_t public;
/** glob data */
glob_t glob;
- /** current match */
- char **match;
+ /** iteration count */
+ u_int pos;
/** absolute path of current file */
char full[PATH_MAX];
} glob_enum_t;
@@ -191,12 +191,13 @@ static void destroy_glob_enum(glob_enum_t *this)
*/
static bool enumerate_glob_enum(glob_enum_t *this, char **file, struct stat *st)
{
- char *match = *(++this->match);
+ char *match;
- if (!match)
+ if (this->pos >= this->glob.gl_pathc)
{
return FALSE;
}
+ match = this->glob.gl_pathv[this->pos++];
if (file)
{
*file = match;
@@ -231,12 +232,9 @@ enumerator_t* enumerator_create_glob(const char *pattern)
.enumerate = (void*)enumerate_glob_enum,
.destroy = (void*)destroy_glob_enum,
},
- .glob = {
- .gl_offs = 1, /* reserve one slot so we can enumerate easily */
- }
);
- status = glob(pattern, GLOB_DOOFFS | GLOB_ERR, NULL, &this->glob);
+ status = glob(pattern, GLOB_ERR, NULL, &this->glob);
if (status == GLOB_NOMATCH)
{
DBG1(DBG_LIB, "no files found matching '%s'", pattern);
@@ -246,7 +244,6 @@ enumerator_t* enumerator_create_glob(const char *pattern)
DBG1(DBG_LIB, "expanding file pattern '%s' failed: %s", pattern,
strerror(errno));
}
- this->match = this->glob.gl_pathv;
return &this->public;
}