1CURLOPT_WRITEFUNCTION(3) curl_easy_setopt options CURLOPT_WRITEFUNCTION(3)
2
3
4
6 CURLOPT_WRITEFUNCTION - set callback for writing received data
7
9 #include <curl/curl.h>
10
11 size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
12
13 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_WRITEFUNCTION, write_callback);
14
16 Pass a pointer to your callback function, which should match the proto‐
17 type shown above.
18
19 This callback function gets called by libcurl as soon as there is data
20 received that needs to be saved. ptr points to the delivered data, and
21 the size of that data is nmemb; size is always 1.
22
23 The callback function will be passed as much data as possible in all
24 invokes, but you must not make any assumptions. It may be one byte, it
25 may be thousands. The maximum amount of body data that will be passed
26 to the write callback is defined in the curl.h header file:
27 CURL_MAX_WRITE_SIZE (the usual default is 16K). If CURLOPT_HEADER(3) is
28 enabled, which makes header data get passed to the write callback, you
29 can get up to CURL_MAX_HTTP_HEADER bytes of header data passed into it.
30 This usually means 100K.
31
32 This function may be called with zero bytes data if the transferred
33 file is empty.
34
35 The data passed to this function will not be zero terminated!
36
37 Set the userdata argument with the CURLOPT_WRITEDATA(3) option.
38
39 Your callback should return the number of bytes actually taken care of.
40 If that amount differs from the amount passed to your callback func‐
41 tion, it'll signal an error condition to the library. This will cause
42 the transfer to get aborted and the libcurl function used will return
43 CURLE_WRITE_ERROR.
44
45 If your callback function returns CURL_WRITEFUNC_PAUSE it will cause
46 this transfer to become paused. See curl_easy_pause(3) for further
47 details.
48
49 Set this option to NULL to get the internal default function used
50 instead of your callback. The internal default function will write the
51 data to the FILE * given with CURLOPT_WRITEDATA(3).
52
54 libcurl will use 'fwrite' as a callback by default.
55
57 For all protocols
58
60 Support for the CURL_WRITEFUNC_PAUSE return code was added in version
61 7.18.0.
62
64 This will return CURLE_OK.
65
67 A common technique is to use this callback to store the incoming data
68 into a dynamically growing allocated buffer. Like in the getinmemory
69 example: https://curl.haxx.se/libcurl/c/getinmemory.html
70
72 CURLOPT_WRITEDATA(3), CURLOPT_READFUNCTION(3),
73
74
75
76libcurl 7.61.1 July 24, 2018 CURLOPT_WRITEFUNCTION(3)