diff options
author | Daniel Stenberg <daniel@haxx.se> | 2018-05-31 15:57:54 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2018-06-01 12:29:21 +0200 |
commit | a115c6bbe73175ad6157fce67338d4a18ed768b2 (patch) | |
tree | 96ebcf5ff201b42740454ece0e6049a37f17d403 /lib/curl_fnmatch.c | |
parent | 6d8c6289122dad7f0a05b6363d8e3c2cc73d096a (diff) |
fnmatch: use the system one if available
If configure detects fnmatch to be available, use that instead of our
custom one for FTP wildcard pattern matching. For standard compliance,
to reduce our footprint and to use already well tested and well
exercised code.
A POSIX fnmatch behaves slightly different than the internal function
for a few test patterns currently and the macOS one yet slightly
different. Test case 1307 is adjusted for these differences.
Closes #2626
Diffstat (limited to 'lib/curl_fnmatch.c')
-rw-r--r-- | lib/curl_fnmatch.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/curl_fnmatch.c b/lib/curl_fnmatch.c index bd4e61f4e..e8aff6761 100644 --- a/lib/curl_fnmatch.c +++ b/lib/curl_fnmatch.c @@ -30,6 +30,17 @@ /* The last #include file should be: */ #include "memdebug.h" +#ifndef HAVE_FNMATCH + +/* + * TODO: + * + * Make this function match POSIX. Test 1307 includes a set of test patterns + * that returns different results with a POSIX fnmatch() than with this + * implemenation and this is considered a bug where POSIX is the guiding + * light. + */ + #define CURLFNM_CHARSET_LEN (sizeof(char) * 256) #define CURLFNM_CHSET_SIZE (CURLFNM_CHARSET_LEN + 15) @@ -357,3 +368,29 @@ int Curl_fnmatch(void *ptr, const char *pattern, const char *string) } return loop((unsigned char *)pattern, (unsigned char *)string, 2); } +#else +#include <fnmatch.h> +/* + * @unittest: 1307 + */ +int Curl_fnmatch(void *ptr, const char *pattern, const char *string) +{ + int rc; + (void)ptr; /* the argument is specified by the curl_fnmatch_callback + prototype, but not used by Curl_fnmatch() */ + if(!pattern || !string) { + return CURL_FNMATCH_FAIL; + } + rc = fnmatch(pattern, string, 0); + switch(rc) { + case 0: + return CURL_FNMATCH_MATCH; + case FNM_NOMATCH: + return CURL_FNMATCH_NOMATCH; + default: + return CURL_FNMATCH_FAIL; + } + /* not reached */ +} + +#endif |