xref: /curl/docs/libcurl/curl_easy_init.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_easy_init
5Section: 3
6Source: libcurl
7See-also:
8  - curl_easy_cleanup (3)
9  - curl_easy_duphandle (3)
10  - curl_easy_perform (3)
11  - curl_easy_reset (3)
12  - curl_global_init (3)
13  - curl_multi_init (3)
14Protocol:
15  - All
16Added-in: 7.1
17---
18
19# NAME
20
21curl_easy_init - create an easy handle
22
23# SYNOPSIS
24
25~~~c
26#include <curl/curl.h>
27
28CURL *curl_easy_init();
29~~~
30
31# DESCRIPTION
32
33This function allocates and returns a CURL easy handle. Such a handle is used
34as input to other functions in the easy interface. This call must have a
35corresponding call to curl_easy_cleanup(3) when the operation is complete.
36
37The easy handle is used to hold and control a single network transfer. It is
38encouraged to reuse easy handles for repeated transfers.
39
40An alternative way to get a new easy handle is to duplicate an already
41existing one with curl_easy_duphandle(3), which has the upside that it gets
42all the options that were set in the source handle set in the new copy as
43well.
44
45If you did not already call curl_global_init(3) before calling this function,
46curl_easy_init(3) does it automatically. This can be lethal in multi-threaded
47cases for platforms where curl_global_init(3) is not thread-safe, and it may
48then result in resource problems because there is no corresponding cleanup.
49
50You are strongly advised to not allow this automatic behavior, by calling
51curl_global_init(3) yourself properly. See the description in libcurl(3) of
52global environment requirements for details of how to use this function.
53
54# %PROTOCOLS%
55
56# EXAMPLE
57
58~~~c
59int main(void)
60{
61  CURL *curl = curl_easy_init();
62  if(curl) {
63    CURLcode res;
64    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
65    res = curl_easy_perform(curl);
66    curl_easy_cleanup(curl);
67  }
68}
69~~~
70
71# %AVAILABILITY%
72
73# RETURN VALUE
74
75If this function returns NULL, something went wrong and you cannot use the
76other curl functions.
77