CURLSHOPT_USERDATA(3)

πŸ’… CURLSHOPT_USERDATA(3) πŸ’…

okay so bestie, welcome to the libcurl Library Functions Manual page for CURLSHOPT_USERDATA β€” and yes this is exactly as niche and iconic as it sounds πŸŽ€


✨ NAME ✨

CURLSHOPT_USERDATA β€” the pointer that gets passed to the lock and unlock mutex callbacks 🫢


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLSHcode curl_share_setopt(CURLSH *share, CURLSHOPT_USERDATA, void *clientp);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea, bestie: libcurl holds onto that clientp parameter verbatim β€” like, it does not copy it, does not peek inside, does not judge it, nothing. It just holds it. πŸ’€

And then it passes that same thing on as the clientp argument to the callbacks you set up with CURLSHOPT_LOCKFUNC(3) and CURLSHOPT_UNLOCKFUNC(3). That's it. That's the whole job. Hand it a pointer, it hands it back to your callbacks. Simple, clean, slay. ✨


🌈 PROTOCOLS 🌈

This functionality affects all supported protocols πŸ‘‘ (all of them, no cap)


πŸ“ EXAMPLE πŸ“

struct secrets {
  void *custom;
};

int main(void)
{
  CURLSHcode sh;
  struct secrets private_stuff;
  CURLSH *share = curl_share_init();
  sh = curl_share_setopt(share, CURLSHOPT_USERDATA, &private_stuff);
  if(sh)
    printf("Error: %s\n", curl_share_strerror(sh));
}

look at her go 😭 she's passing &private_stuff in and letting libcurl hold it. main character pointer energy fr fr.


⭐ AVAILABILITY ⭐

Added in curl 7.10.3 β€” retro icon behavior, honestly πŸ’œ


πŸ’– RETURN VALUE πŸ’–

CURLSHE_OK (zero) means that the option was set properly πŸŽ‰ β€” non-zero means an error occurred πŸ™ˆ. See libcurl-errors(3) for the full list with descriptions, iykyk.


🧚 SEE ALSO 🧚


πŸ’… reminder bestie: libcurl holds your clientp verbatim β€” it does not copy it. So keep that memory alive for as long as your callbacks might need it. No dangling pointers on my watch 🫢

mwah, that's a wrap πŸŽ€ brought to you by libcurl, dated 2026-10-12, from the CURLSHOPT_USERDATA(3) page β€” go forth and share responsibly, queen πŸ‘‘βœ¨

πŸ“¦ where this page comes from