Imported Upstream version 7.40.0
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_WRITEFUNCTION.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
9 .\" *
10 .\" * This software is licensed as described in the file COPYING, which
11 .\" * you should have received as part of this distribution. The terms
12 .\" * are also available at http://curl.haxx.se/docs/copyright.html.
13 .\" *
14 .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 .\" * copies of the Software, and permit persons to whom the Software is
16 .\" * furnished to do so, under the terms of the COPYING file.
17 .\" *
18 .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 .\" * KIND, either express or implied.
20 .\" *
21 .\" **************************************************************************
22 .\"
23 .TH CURLOPT_WRITEFUNCTION 3 "16 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
24 .SH NAME
25 CURLOPT_WRITEFUNCTION \- set callback for writing received data
26 .SH SYNOPSIS
27 .nf
28 #include <curl/curl.h>
29
30 size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
31
32 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_WRITEFUNCTION, write_callback);
33 .SH DESCRIPTION
34 Pass a pointer to your callback function, which should match the prototype
35 shown above.
36
37 This callback function gets called by libcurl as soon as there is data
38 received that needs to be saved.  \fIptr\fP points to the delivered data, and
39 the size of that data is \fIsize\fP multiplied with \fInmemb\fP.
40
41 The callback function will be passed as much data as possible in all invokes,
42 but you must not make any assumptions. It may be one byte, it may be
43 thousands. The maximum amount of body data that will be passed to the write
44 callback is defined in the curl.h header file: \fICURL_MAX_WRITE_SIZE\fP (the
45 usual default is 16K). If \fICURLOPT_HEADER(3)\fP is enabled, which makes
46 header data get passed to the write callback, you can get up to
47 \fICURL_MAX_HTTP_HEADER\fP bytes of header data passed into it. This usually
48 means 100K.
49
50 This function may be called with zero bytes data if the transferred file is
51 empty.
52
53 The data passed to this function will not be zero terminated!
54
55 Set the \fIuserdata\fP argument with the \fICURLOPT_WRITEDATA(3)\fP option.
56
57 Your callback should return the number of bytes actually taken care of. If
58 that amount differs from the amount passed to your callback function, it'll
59 signal an error condition to the library. This will cause the transfer to get
60 aborted and the libcurl function used will return \fICURLE_WRITE_ERROR\fP.
61
62 If your callback function returns CURL_WRITEFUNC_PAUSE it will cause this
63 transfer to become paused.  See \fIcurl_easy_pause(3)\fP for further details.
64
65 Set this option to NULL to get the internal default function used instead of
66 your callback. The internal default function will write the data to the FILE *
67 given with \fICURLOPT_WRITEDATA(3)\fP.
68 .SH DEFAULT
69 libcurl will use 'fwrite' as a callback by default.
70 .SH PROTOCOLS
71 For all protocols
72 .SH AVAILABILITY
73 Support for the CURL_WRITEFUNC_PAUSE return code was added in version 7.18.0.
74 .SH RETURN VALUE
75 This will return CURLE_OK.
76 .SH EXAMPLE
77 A common technique is to use this callback to store the incoming data into a
78 dynamically growing allocated buffer. Like in the getinmemory example:
79 http://curl.haxx.se/libcurl/c/getinmemory.html
80 .SH "SEE ALSO"
81 .BR CURLOPT_WRITEDATA "(3), " CURLOPT_READFUNCTION "(3), "