a54dcd4129e24dcb0d3c4c825241565c21b60160
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_WRITEFUNCTION.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2  "http://www.w3.org/TR/html4/loose.dtd">
3 <html><head>
4 <title>CURLOPT_WRITEFUNCTION man page</title>
5 <meta name="generator" content="roffit">
6 <STYLE type="text/css">
7 pre {
8   overflow: auto;
9   margin: 0;
10 }
11
12 P.level0, pre.level0 {
13  padding-left: 2em;
14 }
15
16 P.level1, pre.level1 {
17  padding-left: 4em;
18 }
19
20 P.level2, pre.level2 {
21  padding-left: 6em;
22 }
23
24 span.emphasis {
25  font-style: italic;
26 }
27
28 span.bold {
29  font-weight: bold;
30 }
31
32 span.manpage {
33  font-weight: bold;
34 }
35
36 h2.nroffsh {
37  background-color: #e0e0e0;
38 }
39
40 span.nroffip {
41  font-weight: bold;
42  font-size: 120%;
43  font-family: monospace;
44 }
45
46 p.roffit {
47  text-align: center;
48  font-size: 80%;
49 }
50 </STYLE>
51 </head><body>
52
53 <p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
54 <p class="level0">CURLOPT_WRITEFUNCTION - set callback for writing received data <a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
55 <p class="level0"><pre class="level0">
56 &#35;include &lt;curl/curl.h&gt;
57 &nbsp;
58 size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
59 &nbsp;
60 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_WRITEFUNCTION, write_callback);
61 </pre>
62 <a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
63 <p class="level0">Pass a pointer to your callback function, which should match the prototype shown above. 
64 <p class="level0">This callback function gets called by libcurl as soon as there is data received that needs to be saved.  <span Class="emphasis">ptr</span> points to the delivered data, and the size of that data is <span Class="emphasis">size</span> multiplied with <span Class="emphasis">nmemb</span>. 
65 <p class="level0">The callback function will be passed as much data as possible in all invokes, but you must not make any assumptions. It may be one byte, it may be thousands. The maximum amount of body data that will be passed to the write callback is defined in the curl.h header file: <span Class="emphasis">CURL_MAX_WRITE_SIZE</span> (the usual default is 16K). If <a Class="emphasis" href="./CURLOPT_HEADER.html">CURLOPT_HEADER</a> is enabled, which makes header data get passed to the write callback, you can get up to <span Class="emphasis">CURL_MAX_HTTP_HEADER</span> bytes of header data passed into it. This usually means 100K. 
66 <p class="level0">This function may be called with zero bytes data if the transferred file is empty. 
67 <p class="level0">The data passed to this function will not be zero terminated! 
68 <p class="level0">Set the <span Class="emphasis">userdata</span> argument with the <a Class="emphasis" href="./CURLOPT_WRITEDATA.html">CURLOPT_WRITEDATA</a> option. 
69 <p class="level0">Your callback should return the number of bytes actually taken care of. If that amount differs from the amount passed to your callback function, it'll signal an error condition to the library. This will cause the transfer to get aborted and the libcurl function used will return <span Class="emphasis">CURLE_WRITE_ERROR</span>. 
70 <p class="level0">If your callback function returns CURL_WRITEFUNC_PAUSE it will cause this transfer to become paused.  See <span Class="emphasis">curl_easy_pause(3)</span> for further details. 
71 <p class="level0">Set this option to NULL to get the internal default function used instead of your callback. The internal default function will write the data to the FILE * given with <a Class="emphasis" href="./CURLOPT_WRITEDATA.html">CURLOPT_WRITEDATA</a>. <a name="DEFAULT"></a><h2 class="nroffsh">DEFAULT</h2>
72 <p class="level0">libcurl will use 'fwrite' as a callback by default. <a name="PROTOCOLS"></a><h2 class="nroffsh">PROTOCOLS</h2>
73 <p class="level0">For all protocols <a name="AVAILABILITY"></a><h2 class="nroffsh">AVAILABILITY</h2>
74 <p class="level0">Support for the CURL_WRITEFUNC_PAUSE return code was added in version 7.18.0. <a name="RETURN"></a><h2 class="nroffsh">RETURN VALUE</h2>
75 <p class="level0">This will return CURLE_OK. <a name="EXAMPLE"></a><h2 class="nroffsh">EXAMPLE</h2>
76 <p class="level0">A common technique is to use this callback to store the incoming data into a dynamically growing allocated buffer. Like in the getinmemory example: <a href="http://curl.haxx.se/libcurl/c/getinmemory.html">http://curl.haxx.se/libcurl/c/getinmemory.html</a> <a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
77 <p class="level0"><a Class="manpage" href="./CURLOPT_WRITEDATA.html">CURLOPT_WRITEDATA</a>, <a Class="manpage" href="./CURLOPT_READFUNCTION.html">CURLOPT_READFUNCTION</a>, <span Class="manpage"> </span> <p class="roffit">
78  This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
79 </body></html>