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