CINXE.COM
libcurl - curl_easy_init()
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>libcurl - curl_easy_init()</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <link rel="stylesheet" type="text/css" href="/curl.css"> <link rel="shortcut icon" href="/favicon.ico"> <link rel="icon" href="/logo/curl-symbol.svg" type="image/svg+xml"> <link rel="alternate" type="application/rss+xml" title="cURL Releases" href="https://github.com/curl/curl/releases.atom"> <link rel="stylesheet" type="text/css" href="/manpage.css"> </head> <body> <div class="main"> <div class="menu"> <a href="/libcurl/c/libcurl.html" class="menuitem" title="Overview">API Overview</a> <div class="dropdown"> <a class="dropbtn" href="/libcurl/c/">Docs</a> <div class="dropdown-content"> <a href="/libcurl/c/libcurl-easy.html">API: easy</a> <a href="/libcurl/c/libcurl-multi.html">API: multi</a> <a href="/libcurl/c/libcurl-share.html">API: share</a> <a href="/libcurl/c/libcurl-url.html">API: URL</a> <a href="/libcurl/c/libcurl-ws.html">API: WebSocket</a> <a href="/libcurl/c/libcurl-env.html">Environment vars</a> <a href="/libcurl/c/libcurl-errors.html">Errors</a> <a href="/libcurl/c/example.html">Examples</a> <a href="/libcurl/security.html">Security</a> <a href="/libcurl/c/symbols-in-versions.html">Symbols</a> <a href="/libcurl/c/libcurl-tutorial.html">Tutorial</a> <hr> <a href="/libcurl/c/easy_setopt_options.html">easy setopt options</a> <a href="/libcurl/c/easy_getinfo_options.html">easy getinfo options</a> <a href="/libcurl/c/multi_setopt_options.html">multi setopt options</a> <a href="/libcurl/c/tls-options.html">TLS options</a> </div> </div> <div class="dropdown"> <a class="dropbtn" href="/libcurl/c/">Functions</a> <div class="dropdown-content"> <a href="/libcurl/c/allfuncs.html">All functions</a> <a href="/libcurl/c/curl_easy_getinfo.html">curl_easy_getinfo</a> <a href="/libcurl/c/curl_easy_init.html">curl_easy_init</a> <a href="/libcurl/c/curl_easy_perform.html">curl_easy_perform</a> <a href="/libcurl/c/curl_easy_reset.html">curl_easy_reset</a> <a href="/libcurl/c/curl_easy_setopt.html">curl_easy_setopt</a> <a href="/libcurl/c/curl_multi_add_handle.html">curl_multi_add_handle</a> <a href="/libcurl/c/curl_multi_init.html">curl_multi_init</a> <a href="/libcurl/c/curl_multi_perform.html">curl_multi_perform</a> <a href="/libcurl/c/curl_multi_remove_handle.html">curl_multi_remove_handle</a> <a href="/libcurl/c/curl_multi_setopt.html">curl_multi_setopt</a> </div> </div> </div> <div class="contents"> <div class="where"><a href="/">curl</a> / <a href="/libcurl/">libcurl</a> / <a href="/libcurl/c/">API</a> / <b>curl_easy_init</b></div> <h1> curl_easy_init - create an easy handle </h1> <div class="relatedbox"> <b>Related:</b> <br><a href="easy_setopt_options.html">easy options</a> <br><a href="easy_getinfo_options.html">getinfo options</a> <br><a href="multi_setopt_options.html">multi options</a> <br><a href="symbols-in-versions.html">Symbols</a> <br><a href="https://github.com/curl/curl/issues/new?title=curl_easy_init%20manpage:&labels=documentation&template=docs.yml&source=curl_easy_init.md" target="_new">File a bug about this page</a> <br><a href="https://github.com/curl/curl/blob/master/docs/libcurl/curl_easy_init.md" target="_new">View manpage source</a> </div> <!-- generated with roffit --> <a name="NAME"></a><h2 class="nroffsh">Name</h2> <p class="level0">curl_easy_init - create an easy handle </p><a name="SYNOPSIS"></a><h2 class="nroffsh">Synopsis</h2><pre class="level0"> #include <curl/curl.h> CURL *<a href="curl_easy_init.html">curl_easy_init</a>(); </pre> <a name="DESCRIPTION"></a><h2 class="nroffsh">Description</h2> <p class="level0">This function allocates and returns a CURL easy handle. Such a handle is used as input to other functions in the easy interface. This call must have a corresponding call to <a Class="emphasis" href="./curl_easy_cleanup.html">curl_easy_cleanup</a> when the operation is complete. </p> <p class="level0">The easy handle is used to hold and control a single network transfer. It is encouraged to reuse easy handles for repeated transfers. </p> <p class="level0">An alternative way to get a new easy handle is to duplicate an already existing one with <a Class="emphasis" href="./curl_easy_duphandle.html">curl_easy_duphandle</a>, which has the upside that it gets all the options that were set in the source handle set in the new copy as well. </p> <p class="level0">If you did not already call <a Class="emphasis" href="./curl_global_init.html">curl_global_init</a> before calling this function, <a Class="emphasis" href="./curl_easy_init.html">curl_easy_init</a> does it automatically. This can be lethal in multi-threaded cases for platforms where <a Class="emphasis" href="./curl_global_init.html">curl_global_init</a> is not thread-safe, and it may then result in resource problems because there is no corresponding cleanup. </p> <p class="level0">You are strongly advised to not allow this automatic behavior, by calling <a Class="emphasis" href="./curl_global_init.html">curl_global_init</a> yourself properly. See the description in <a Class="emphasis" href="./libcurl.html">libcurl</a> of global environment requirements for details of how to use this function. </p><a name="PROTOCOLS"></a><h2 class="nroffsh">Protocols</h2> <p class="level0">This functionality affects all supported protocols </p><a name="EXAMPLE"></a><h2 class="nroffsh">Example</h2><pre class="level0"> int main(void) { CURL *curl = <a href="curl_easy_init.html">curl_easy_init</a>(); if(curl) { CURLcode res; <a href="curl_easy_setopt.html">curl_easy_setopt</a>(curl, <a href="CURLOPT_URL.html">CURLOPT_URL</a>, "https://example.com"); res = <a href="curl_easy_perform.html">curl_easy_perform</a>(curl); <a href="curl_easy_cleanup.html">curl_easy_cleanup</a>(curl); } } </pre> <a name="AVAILABILITY"></a><h2 class="nroffsh">Availability</h2> <p class="level0">Added in curl <a href="/ch/7.1.html">7.1</a> </p><a name="RETURN"></a><h2 class="nroffsh">Return value</h2> <p class="level0">If this function returns NULL, something went wrong and you cannot use the other curl functions. </p><a name="SEE"></a><h2 class="nroffsh">See also</h2> <p class="level0"><a Class="bold" href="./curl_easy_cleanup.html">curl_easy_cleanup</a>(3), <a Class="bold" href="./curl_easy_duphandle.html">curl_easy_duphandle</a>(3), <a Class="bold" href="./curl_easy_perform.html">curl_easy_perform</a>(3), <a Class="bold" href="./curl_easy_reset.html">curl_easy_reset</a>(3), <a Class="bold" href="./curl_global_init.html">curl_global_init</a>(3), <a Class="bold" href="./curl_multi_init.html">curl_multi_init</a>(3) </p><p class="roffit"> This HTML page was made with <a href="https://daniel.haxx.se/projects/roffit/">roffit</a>. </div> </div> </body> </html>