CURLOPT_CHUNK_END_FUNCTION.md (1655B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_CHUNK_END_FUNCTION 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_CHUNK_BGN_FUNCTION (3) 9 - CURLOPT_WILDCARDMATCH (3) 10 Protocol: 11 - FTP 12 Added-in: 7.21.0 13 --- 14 15 # NAME 16 17 CURLOPT_CHUNK_END_FUNCTION - callback after a transfer with FTP wildcard match 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 long chunk_end_callback(void *ptr); 25 26 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CHUNK_END_FUNCTION, 27 chunk_end_callback); 28 ~~~ 29 30 # DESCRIPTION 31 32 Pass a pointer to your callback function, which should match the prototype 33 shown above. 34 35 This function gets called by libcurl as soon as a part of the stream has been 36 transferred (or skipped). 37 38 Return *CURL_CHUNK_END_FUNC_OK* if everything is fine or 39 **CURL_CHUNK_END_FUNC_FAIL** to tell the lib to stop if some error occurred. 40 41 # DEFAULT 42 43 NULL 44 45 # %PROTOCOLS% 46 47 # EXAMPLE 48 49 ~~~c 50 #include <stdio.h> 51 52 struct callback_data { 53 FILE *output; 54 }; 55 56 static long file_is_downloaded(void *ptr) 57 { 58 struct callback_data *data = ptr; 59 if(data->output) { 60 fclose(data->output); 61 data->output = 0x0; 62 } 63 return CURL_CHUNK_END_FUNC_OK; 64 } 65 66 int main() 67 { 68 /* data for callback */ 69 struct callback_data callback_info; 70 71 CURL *curl = curl_easy_init(); 72 73 curl_easy_setopt(curl, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded); 74 curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info); 75 } 76 ~~~ 77 78 # %AVAILABILITY% 79 80 # RETURN VALUE 81 82 curl_easy_setopt(3) returns a CURLcode indicating success or error. 83 84 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 85 libcurl-errors(3).