xref: /aosp_15_r20/external/curl/docs/libcurl/curl_easy_init.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: curl_easy_init
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - curl_easy_cleanup (3)
9*6236dae4SAndroid Build Coastguard Worker  - curl_easy_duphandle (3)
10*6236dae4SAndroid Build Coastguard Worker  - curl_easy_perform (3)
11*6236dae4SAndroid Build Coastguard Worker  - curl_easy_reset (3)
12*6236dae4SAndroid Build Coastguard Worker  - curl_global_init (3)
13*6236dae4SAndroid Build Coastguard Worker  - curl_multi_init (3)
14*6236dae4SAndroid Build Coastguard WorkerProtocol:
15*6236dae4SAndroid Build Coastguard Worker  - All
16*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1
17*6236dae4SAndroid Build Coastguard Worker---
18*6236dae4SAndroid Build Coastguard Worker
19*6236dae4SAndroid Build Coastguard Worker# NAME
20*6236dae4SAndroid Build Coastguard Worker
21*6236dae4SAndroid Build Coastguard Workercurl_easy_init - create an easy handle
22*6236dae4SAndroid Build Coastguard Worker
23*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard Worker~~~c
26*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard WorkerCURL *curl_easy_init();
29*6236dae4SAndroid Build Coastguard Worker~~~
30*6236dae4SAndroid Build Coastguard Worker
31*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
32*6236dae4SAndroid Build Coastguard Worker
33*6236dae4SAndroid Build Coastguard WorkerThis function allocates and returns a CURL easy handle. Such a handle is used
34*6236dae4SAndroid Build Coastguard Workeras input to other functions in the easy interface. This call must have a
35*6236dae4SAndroid Build Coastguard Workercorresponding call to curl_easy_cleanup(3) when the operation is complete.
36*6236dae4SAndroid Build Coastguard Worker
37*6236dae4SAndroid Build Coastguard WorkerThe easy handle is used to hold and control a single network transfer. It is
38*6236dae4SAndroid Build Coastguard Workerencouraged to reuse easy handles for repeated transfers.
39*6236dae4SAndroid Build Coastguard Worker
40*6236dae4SAndroid Build Coastguard WorkerAn alternative way to get a new easy handle is to duplicate an already
41*6236dae4SAndroid Build Coastguard Workerexisting one with curl_easy_duphandle(3), which has the upside that it gets
42*6236dae4SAndroid Build Coastguard Workerall the options that were set in the source handle set in the new copy as
43*6236dae4SAndroid Build Coastguard Workerwell.
44*6236dae4SAndroid Build Coastguard Worker
45*6236dae4SAndroid Build Coastguard WorkerIf you did not already call curl_global_init(3) before calling this function,
46*6236dae4SAndroid Build Coastguard Workercurl_easy_init(3) does it automatically. This can be lethal in multi-threaded
47*6236dae4SAndroid Build Coastguard Workercases for platforms where curl_global_init(3) is not thread-safe, and it may
48*6236dae4SAndroid Build Coastguard Workerthen result in resource problems because there is no corresponding cleanup.
49*6236dae4SAndroid Build Coastguard Worker
50*6236dae4SAndroid Build Coastguard WorkerYou are strongly advised to not allow this automatic behavior, by calling
51*6236dae4SAndroid Build Coastguard Workercurl_global_init(3) yourself properly. See the description in libcurl(3) of
52*6236dae4SAndroid Build Coastguard Workerglobal environment requirements for details of how to use this function.
53*6236dae4SAndroid Build Coastguard Worker
54*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
55*6236dae4SAndroid Build Coastguard Worker
56*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
57*6236dae4SAndroid Build Coastguard Worker
58*6236dae4SAndroid Build Coastguard Worker~~~c
59*6236dae4SAndroid Build Coastguard Workerint main(void)
60*6236dae4SAndroid Build Coastguard Worker{
61*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
62*6236dae4SAndroid Build Coastguard Worker  if(curl) {
63*6236dae4SAndroid Build Coastguard Worker    CURLcode res;
64*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
65*6236dae4SAndroid Build Coastguard Worker    res = curl_easy_perform(curl);
66*6236dae4SAndroid Build Coastguard Worker    curl_easy_cleanup(curl);
67*6236dae4SAndroid Build Coastguard Worker  }
68*6236dae4SAndroid Build Coastguard Worker}
69*6236dae4SAndroid Build Coastguard Worker~~~
70*6236dae4SAndroid Build Coastguard Worker
71*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
74*6236dae4SAndroid Build Coastguard Worker
75*6236dae4SAndroid Build Coastguard WorkerIf this function returns NULL, something went wrong and you cannot use the
76*6236dae4SAndroid Build Coastguard Workerother curl functions.
77