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