Make availability of glob(3) optional in settings_t.

If glob(3) is not available just try to open the pattern as regular
file. The reason for this change is that glob(3) is not available on Android.
This commit is contained in:
Tobias Brunner
2011-03-22 19:21:26 +01:00
parent 913591ecb8
commit a6390879d5
2 changed files with 35 additions and 22 deletions
+1 -1
View File
@@ -348,7 +348,7 @@ AC_CHECK_FUNCS(prctl)
AC_CHECK_FUNCS(mallinfo) AC_CHECK_FUNCS(mallinfo)
AC_CHECK_HEADERS(sys/sockio.h) AC_CHECK_HEADERS(sys/sockio.h glob.h)
AC_CHECK_HEADERS(net/pfkeyv2.h netipsec/ipsec.h netinet6/ipsec.h linux/udp.h) AC_CHECK_HEADERS(net/pfkeyv2.h netipsec/ipsec.h netinet6/ipsec.h linux/udp.h)
AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [], AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [],
+34 -21
View File
@@ -20,12 +20,15 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <glob.h>
#include <libgen.h> #include <libgen.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_GLOB_H
#include <glob.h>
#endif /* HAVE_GLOB_H */
#include "settings.h" #include "settings.h"
#include "debug.h" #include "debug.h"
@@ -969,16 +972,15 @@ static bool parse_file(linked_list_t *contents, char *file, int level,
} }
/** /**
* Load the files matching "pattern", which is resolved with glob(3). * Load the files matching "pattern", which is resolved with glob(3), if
* available.
* If the pattern is relative, the directory of "file" is used as base. * If the pattern is relative, the directory of "file" is used as base.
*/ */
static bool parse_files(linked_list_t *contents, char *file, int level, static bool parse_files(linked_list_t *contents, char *file, int level,
char *pattern, section_t *section) char *pattern, section_t *section)
{ {
bool success = TRUE; bool success = TRUE;
int status; char pat[PATH_MAX];
glob_t buf;
char **expanded, pat[PATH_MAX];
if (level > MAX_INCLUSION_LEVEL) if (level > MAX_INCLUSION_LEVEL)
{ {
@@ -1013,28 +1015,39 @@ static bool parse_files(linked_list_t *contents, char *file, int level,
} }
free(dir); free(dir);
} }
status = glob(pat, GLOB_ERR, NULL, &buf); #ifdef HAVE_GLOB_H
if (status == GLOB_NOMATCH)
{ {
DBG2(DBG_LIB, "no files found matching '%s', ignored", pat); int status;
} glob_t buf;
else if (status != 0)
{ status = glob(pat, GLOB_ERR, NULL, &buf);
DBG1(DBG_LIB, "expanding file pattern '%s' failed", pat); if (status == GLOB_NOMATCH)
success = FALSE;
}
else
{
for (expanded = buf.gl_pathv; *expanded != NULL; expanded++)
{ {
success &= parse_file(contents, *expanded, level + 1, section); DBG2(DBG_LIB, "no files found matching '%s', ignored", pat);
if (!success) }
else if (status != 0)
{
DBG1(DBG_LIB, "expanding file pattern '%s' failed", pat);
success = FALSE;
}
else
{
char **expanded;
for (expanded = buf.gl_pathv; *expanded != NULL; expanded++)
{ {
break; success &= parse_file(contents, *expanded, level + 1, section);
if (!success)
{
break;
}
} }
} }
globfree(&buf);
} }
globfree(&buf); #else /* HAVE_GLOB_H */
/* if glob(3) is not available, try to load pattern directly */
success = parse_file(contents, pat, level + 1, section);
#endif /* HAVE_GLOB_H */
return success; return success;
} }