1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_FNMATCH_FUNCTION 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_DEBUGFUNCTION (3) 9 - CURLOPT_FNMATCH_DATA (3) 10 - CURLOPT_WILDCARDMATCH (3) 11Protocol: 12 - FTP 13--- 14 15# NAME 16 17CURLOPT_FNMATCH_FUNCTION - wildcard match callback 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24int fnmatch_callback(void *ptr, 25 const char *pattern, 26 const char *string); 27 28CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FNMATCH_FUNCTION, 29 fnmatch_callback); 30~~~ 31 32# DESCRIPTION 33 34Pass a pointer to your callback function, which should match the prototype 35shown above. 36 37This callback is used for wildcard matching. 38 39Return *CURL_FNMATCHFUNC_MATCH* if pattern matches the string, 40*CURL_FNMATCHFUNC_NOMATCH* if not or *CURL_FNMATCHFUNC_FAIL* if an 41error occurred. 42 43# DEFAULT 44 45NULL == an internal function for wildcard matching. 46 47# EXAMPLE 48 49~~~c 50extern int string_match(const char *s1, const char *s2); 51 52struct local_stuff { 53 void *custom; 54}; 55static int my_fnmatch(void *clientp, 56 const char *pattern, const char *string) 57{ 58 struct local_stuff *data = clientp; 59 printf("my pointer: %p\n", data->custom); 60 if(string_match(pattern, string)) 61 return CURL_FNMATCHFUNC_MATCH; 62 else 63 return CURL_FNMATCHFUNC_NOMATCH; 64} 65 66int main(void) 67{ 68 struct local_stuff local_data; 69 CURL *curl = curl_easy_init(); 70 if(curl) { 71 curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/file*"); 72 curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 1L); 73 curl_easy_setopt(curl, CURLOPT_FNMATCH_FUNCTION, my_fnmatch); 74 curl_easy_setopt(curl, CURLOPT_FNMATCH_DATA, &local_data); 75 curl_easy_perform(curl); 76 } 77} 78~~~ 79 80# AVAILABILITY 81 82Added in 7.21.0 83 84# RETURN VALUE 85 86Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 87