xref: /curl/docs/libcurl/opts/CURLOPT_PRIVATE.md (revision e3fe0200)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_PRIVATE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_PRIVATE (3)
9  - CURLOPT_STDERR (3)
10  - CURLOPT_VERBOSE (3)
11Protocol:
12  - All
13---
14
15# NAME
16
17CURLOPT_PRIVATE - store a private pointer
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PRIVATE, void *pointer);
25~~~
26
27# DESCRIPTION
28
29Pass a void * as parameter, pointing to data that should be associated with
30this curl handle. The pointer can subsequently be retrieved using
31curl_easy_getinfo(3) with the CURLINFO_PRIVATE(3) option. libcurl itself
32never does anything with this data.
33
34# DEFAULT
35
36NULL
37
38# EXAMPLE
39
40~~~c
41struct private {
42  void *custom;
43};
44
45int main(void)
46{
47  CURL *curl = curl_easy_init();
48  struct private secrets;
49  if(curl) {
50    struct private *extracted;
51    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
52
53    /* store a pointer to our private struct */
54    curl_easy_setopt(curl, CURLOPT_PRIVATE, &secrets);
55
56    curl_easy_perform(curl);
57
58    /* we can extract the private pointer again too */
59    curl_easy_getinfo(curl, CURLINFO_PRIVATE, &extracted);
60  }
61}
62~~~
63
64# AVAILABILITY
65
66Added in 7.10.3
67
68# RETURN VALUE
69
70Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
71