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