CURLOPT_PROGRESSDATA.md (1572B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_PROGRESSDATA 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_PROGRESSFUNCTION (3) 9 - CURLOPT_XFERINFOFUNCTION (3) 10 Protocol: 11 - All 12 Added-in: 7.1 13 --- 14 15 # NAME 16 17 CURLOPT_PROGRESSDATA - pointer passed to the progress callback 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROGRESSDATA, void *pointer); 25 ~~~ 26 27 # DESCRIPTION 28 29 Pass a *pointer* that is untouched by libcurl and passed as the first 30 argument in the progress callback set with CURLOPT_PROGRESSFUNCTION(3). 31 32 # DEFAULT 33 34 NULL 35 36 # %PROTOCOLS% 37 38 # EXAMPLE 39 40 ~~~c 41 struct progress { 42 char *private; 43 size_t size; 44 }; 45 46 static int progress_callback(void *clientp, 47 double dltotal, 48 double dlnow, 49 double ultotal, 50 double ulnow) 51 { 52 struct progress *memory = clientp; 53 printf("private: %p\n", memory->private); 54 55 /* use the values */ 56 57 return 0; /* all is good */ 58 } 59 60 int main(void) 61 { 62 CURL *curl = curl_easy_init(); 63 if(curl) { 64 struct progress data; 65 66 /* pass struct to callback */ 67 curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data); 68 curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); 69 70 curl_easy_perform(curl); 71 } 72 } 73 ~~~ 74 75 # %AVAILABILITY% 76 77 # RETURN VALUE 78 79 curl_easy_setopt(3) returns a CURLcode indicating success or error. 80 81 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 82 libcurl-errors(3).