curl_share_init(3)

✨ curl_share_init β€” bestie, let's make a share object πŸŽ€

okay so real talk, we're deep in the libcurl section of the manual today and the star of the show is curl_share_init from the Library Functions Manual. she's short, she's sweet, and she's the main character of every share-handle origin story. πŸ’…


🌸 NAME 🌸

curl_share_init β€” create a share object ✨

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

CURLSH *curl_share_init();

πŸ’– DESCRIPTION πŸ’–

So this function hands you back a pointer to a CURLSH handle, and that handle is literally the input to all the other share-functions. Some spots in the docs call it a "share handle" β€” same thing, different nickname, iykyk. 🫢

⚠️ okay this part is non-negotiable: this init call MUST have a corresponding call to curl_share_cleanup(3) when all operations using the share are complete. not "should", not "maybe later" β€” MUST. don't leave her hanging. 😭

And what do you even do with this handle? You pass it to curl via the CURLOPT_SHARE(3) option with curl_easy_setopt(3) β€” that's how you make that specific curl handle use the data in this share. one share, many handles, everyone's sharing, it's giving community. πŸ‘‘

🌈 PROTOCOLS 🌈

This functionality affects all supported protocols. every single one. no cap. ⭐

πŸ“ EXAMPLE πŸ“

int main(void)
{
  CURLSHcode sh;
  CURLSH *share = curl_share_init();
  sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
  if(sh)
    printf("Error: %s\n", curl_share_strerror(sh));
}

look at her go β€” init the share, set an option, check the code, print the error string if it's not zero. iconic behavior honestly. πŸ’œ

🧚 AVAILABILITY 🧚

Added in curl 7.10 ✨ (yes she's been around a while, a true veteran)

πŸ‘‘ RETURN VALUE πŸ‘‘

If this function returns NULL, something went wrong (out of memory, etc.) and therefore the share object was not created. πŸ’€ so like, always vibe check that pointer before you use it, bestie.

πŸ’… SEE ALSO πŸ’…


fr fr that's the whole page β€” sending you a million heart emojis from the libcurl manual, dated 2026-10-12, and yes that footer is real: this one's from libcurl, so go forth and share responsibly πŸ¦‹πŸ’–πŸŽ€

πŸ“¦ where this page comes from