CURLOPT_CH...D_FUNCTION(3)

πŸ’… CURLOPT_CH...D_FUNCTION(3) πŸ’…

ok so quick vibe check: this is a Library Functions Manual page, bestie β€” specifically CURLOPT_CH...D_FUNCTION(3). yes the title is literally truncated with dots, that's just how it's printed, don't come for me 😭


✨ NAME ✨

CURLOPT_CHUNK_END_FUNCTION β€” the callback that fires after a transfer with FTP wildcard match πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

long chunk_end_callback(void *ptr);

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CHUNK_END_FUNCTION,
                          chunk_end_callback);

🌸 DESCRIPTION 🌸

So you pass in a pointer to your callback function, and it's gotta match the prototype up there ⬆️ β€” long chunk_end_callback(void *ptr), no notes, periodt.

libcurl calls this function the literal second a part of the stream has been transferred (or skipped). it's giving "wrap-up era" β€” like the callback that shows up at the end of the group hang to make sure everyone got home safe 🫢

Your return value is the whole vibe check:

  • return CURL_CHUNK_END_FUNC_OK if everything is, in fact, fine πŸ’–
  • return CURL_CHUNK_END_FUNC_FAIL to tell the lib to stop if some error occurred πŸ’€

πŸŽ€ DEFAULT πŸŽ€

NULL

(no callback, no drama, iconic behaviour honestly)


🌈 PROTOCOLS 🌈

This functionality affects ftp only β€” FTP girlies only, everyone else sit this one out πŸ™ˆ


🧚 EXAMPLE 🧚

#include <stdio.h>

struct callback_data {
   FILE *output;
};

static long file_is_downloaded(void *ptr)
{
  struct callback_data *data = ptr;
  if(data->output) {
    fclose(data->output);
    data->output = 0x0;
  }
  return CURL_CHUNK_END_FUNC_OK;
}

int main()
{
  /* data for callback */
  struct callback_data callback_info;

  CURL *curl = curl_easy_init();

  curl_easy_setopt(curl, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
  curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &callback_info);
}

look at her go β€” closes the file, nulls the pointer to 0x0, returns CURL_CHUNK_END_FUNC_OK. main character energy, truly πŸ‘‘


⭐ AVAILABILITY ⭐

Added in curl 7.21.0 β€” a classic, lowkey vintage, we stan a legacy icon πŸ•°οΈ


πŸ”₯ RETURN VALUE πŸ”₯

curl_easy_setopt(3) returns a CURLcode indicating success or error.

  • CURLE_OK (0) means everything was OK β€” slay βœ…
  • non-zero means an error occurred β€” not slay ❌

(see libcurl-errors(3) for the full list of what went wrong, iykyk)


πŸ‘‘ SEE ALSO πŸ‘‘


ok that's the whole page, go be a wildcard-matching legend πŸ’œ

libcurl Β· 2026-10-12 Β· CURLOPT_CH...D_FUNCTION(3) β€” mwah, bye bestie, see u in the manpages πŸ“βœ¨

πŸ“¦ where this page comes from