diff options
author | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2004-03-05 19:52:06 +0000 |
---|---|---|
committer | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2004-03-05 19:52:06 +0000 |
commit | a51a39237632944ebfcdaa42f64d750e528441a5 (patch) | |
tree | a343948762170d06103f735721951569283eb1ce /strings/apr_fnmatch.c | |
parent | a32e53947455d0b057ae167f853728c1abe08d6e (diff) | |
download | libapr-a51a39237632944ebfcdaa42f64d750e528441a5.tar.gz |
Add apr_match_glob and two tests to make sure that it is working. There
is a problem that is documented in the code that requires an
apr_filepath_basename. That will be added soon.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64936 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings/apr_fnmatch.c')
-rw-r--r-- | strings/apr_fnmatch.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/strings/apr_fnmatch.c b/strings/apr_fnmatch.c index 08e2b9bc7..417ac8312 100644 --- a/strings/apr_fnmatch.c +++ b/strings/apr_fnmatch.c @@ -45,8 +45,11 @@ static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94"; #ifndef WIN32 #include "apr_private.h" #endif +#include "apr_file_info.h" #include "apr_fnmatch.h" +#include "apr_tables.h" #include "apr_lib.h" +#include "apr_strings.h" #include <string.h> #if APR_HAVE_CTYPE_H # include <ctype.h> @@ -241,3 +244,50 @@ APR_DECLARE(int) apr_fnmatch_test(const char *pattern) } return 0; } + +/* Find all files matching the specified pattern */ +APR_DECLARE(apr_status_t) apr_match_glob(const char *pattern, + apr_array_header_t **result, + apr_pool_t *p) +{ + apr_dir_t *dir; + apr_finfo_t finfo; + apr_status_t rv; + char *path; + + /* XXX So, this is kind of bogus. Basically, I need to strip any leading + * directories off the pattern, but there is no portable way to do that. + * So, for now we just find the last occurance of '/' and if that doesn't + * return anything, then we look for '\'. This means that we could + * screw up on unix if the pattern is something like "foo\.*" That '\' + * isn't a directory delimiter, it is a part of the filename. To fix this, + * we really need apr_filepath_basename, which will be coming as soon as + * I get to it. rbb + */ + char *idx = strrchr(pattern, '/'); + + if (idx == NULL) { + idx = strrchr(pattern, '\\'); + } + if (idx == NULL) { + path = "."; + } + else { + path = apr_pstrndup(p, pattern, idx - pattern); + pattern = idx + 1; + } + + *result = apr_array_make(p, 0, sizeof(char *)); + rv = apr_dir_open(&dir, path, p); + if (rv != APR_SUCCESS) { + return rv; + } + + while (apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) { + if (apr_fnmatch(pattern, finfo.name, 0) == APR_SUCCESS) { + *(const char **)apr_array_push(*result) = finfo.name; + } + } + apr_dir_close(dir); + return APR_SUCCESS; +} |