113498266Sopenharmony_ci---
213498266Sopenharmony_cic: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
313498266Sopenharmony_ciSPDX-License-Identifier: curl
413498266Sopenharmony_ciTitle: curl_easy_init
513498266Sopenharmony_ciSection: 3
613498266Sopenharmony_ciSource: libcurl
713498266Sopenharmony_ciSee-also:
813498266Sopenharmony_ci  - curl_easy_cleanup (3)
913498266Sopenharmony_ci  - curl_easy_duphandle (3)
1013498266Sopenharmony_ci  - curl_easy_perform (3)
1113498266Sopenharmony_ci  - curl_easy_reset (3)
1213498266Sopenharmony_ci  - curl_global_init (3)
1313498266Sopenharmony_ci  - curl_multi_init (3)
1413498266Sopenharmony_ci---
1513498266Sopenharmony_ci
1613498266Sopenharmony_ci# NAME
1713498266Sopenharmony_ci
1813498266Sopenharmony_cicurl_easy_init - Start a libcurl easy session
1913498266Sopenharmony_ci
2013498266Sopenharmony_ci# SYNOPSIS
2113498266Sopenharmony_ci
2213498266Sopenharmony_ci~~~c
2313498266Sopenharmony_ci#include <curl/curl.h>
2413498266Sopenharmony_ci
2513498266Sopenharmony_ciCURL *curl_easy_init();
2613498266Sopenharmony_ci~~~
2713498266Sopenharmony_ci
2813498266Sopenharmony_ci# DESCRIPTION
2913498266Sopenharmony_ci
3013498266Sopenharmony_ciThis function allocates and returns a CURL easy handle. Such a handle is used
3113498266Sopenharmony_cias input to other functions in the easy interface. This call must have a
3213498266Sopenharmony_cicorresponding call to curl_easy_cleanup(3) when the operation is complete.
3313498266Sopenharmony_ci
3413498266Sopenharmony_ciThe easy handle is used to hold and control a single network transfer. It is
3513498266Sopenharmony_ciencouraged to reuse easy handles for repeated transfers.
3613498266Sopenharmony_ci
3713498266Sopenharmony_ciAn alternative way to get a new easy handle is to duplicate an already
3813498266Sopenharmony_ciexisting one with curl_easy_duphandle(3), which has the upside that it gets
3913498266Sopenharmony_ciall the options that were set in the source handle set in the new copy as
4013498266Sopenharmony_ciwell.
4113498266Sopenharmony_ci
4213498266Sopenharmony_ciIf you did not already call curl_global_init(3) before calling this function,
4313498266Sopenharmony_cicurl_easy_init(3) does it automatically. This may be lethal in multi-threaded
4413498266Sopenharmony_cicases, if curl_global_init(3) is not thread-safe in your system, and it may
4513498266Sopenharmony_cithen result in resource problems because there is no corresponding cleanup.
4613498266Sopenharmony_ci
4713498266Sopenharmony_ciYou are strongly advised to not allow this automatic behavior, by calling
4813498266Sopenharmony_cicurl_global_init(3) yourself properly. See the description in libcurl(3) of
4913498266Sopenharmony_ciglobal environment requirements for details of how to use this function.
5013498266Sopenharmony_ci
5113498266Sopenharmony_ci# EXAMPLE
5213498266Sopenharmony_ci
5313498266Sopenharmony_ci~~~c
5413498266Sopenharmony_ciint main(void)
5513498266Sopenharmony_ci{
5613498266Sopenharmony_ci  CURL *curl = curl_easy_init();
5713498266Sopenharmony_ci  if(curl) {
5813498266Sopenharmony_ci    CURLcode res;
5913498266Sopenharmony_ci    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
6013498266Sopenharmony_ci    res = curl_easy_perform(curl);
6113498266Sopenharmony_ci    curl_easy_cleanup(curl);
6213498266Sopenharmony_ci  }
6313498266Sopenharmony_ci}
6413498266Sopenharmony_ci~~~
6513498266Sopenharmony_ci
6613498266Sopenharmony_ci# AVAILABILITY
6713498266Sopenharmony_ci
6813498266Sopenharmony_ciAlways
6913498266Sopenharmony_ci
7013498266Sopenharmony_ci# RETURN VALUE
7113498266Sopenharmony_ci
7213498266Sopenharmony_ciIf this function returns NULL, something went wrong and you cannot use the
7313498266Sopenharmony_ciother curl functions.
74