curl_url_dup(3)

✨ curl_url_dup(3) ✨

okay so bestie, welcome to the curl_url_dup page β€” it lives in the Library Functions Manual and it's genuinely one of the cutest little functions in libcurl, no cap πŸ’…


🌸 NAME 🌸

curl_url_dup β€” duplicate a URL handle πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

CURLU *curl_url_dup(const CURLU *inhandle);

πŸ’– DESCRIPTION πŸ’–

Okay so picture this: you've got a URL object, and you want a twin. Not a reference, not a vibe, an actual copy. That's literally the whole job here 🫢

curl_url_dup duplicates the URL object that the input CURLU inhandle identifies, and it returns a pointer to that copy as a shiny new CURLU handle ✨

⚠️ bestie listen to me: the new handle also needs to be freed with curl_url_cleanup(3). It's giving "you brought it into this world, you clean it up" 😭 don't ghost it.

🌈 PROTOCOLS 🌈

This functionality affects all supported protocols β€” every single one, periodt πŸ‘‘


πŸ”₯ EXAMPLE πŸ”₯

int main(void)
{
  CURLUcode rc;
  CURLU *url = curl_url();
  CURLU *url2;
  rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
  if(!rc) {
    url2 = curl_url_dup(url); /* clone it */
    curl_url_cleanup(url2);
  }
  curl_url_cleanup(url);
}

see how url2 gets its own curl_url_cleanup(url2) and url gets its own curl_url_cleanup(url)? two handles, two cleanups, that's the main character energy we're going for πŸ’€βœ¨


⭐ AVAILABILITY ⭐

Added in curl 7.62.0 β€” a classic, an icon, a legend πŸŽ€


πŸ’œ RETURN VALUE πŸ’œ

Returns a pointer to a new CURLU handle… or NULL if it's out of memory 😭 (in which case, no handle for you, sorry bestie).


πŸ“ SEE ALSO πŸ“

go read those too, iykyk πŸ’… they're the whole friend group fr fr


mwah πŸ’‹ that's the page β€” brought to you by libcurl, dated 2026-10-12, and it's curl_url_dup(3) out πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from