1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_global_init 5Section: 3 6Source: libcurl 7See-also: 8 - curl_easy_init (3) 9 - curl_global_cleanup (3) 10 - curl_global_init_mem (3) 11 - curl_global_sslset (3) 12 - curl_global_trace (3) 13 - libcurl (3) 14Protocol: 15 - All 16Added-in: 7.8 17--- 18 19# NAME 20 21curl_global_init - global libcurl initialization 22 23# SYNOPSIS 24 25~~~c 26#include <curl/curl.h> 27 28CURLcode curl_global_init(long flags); 29~~~ 30 31# DESCRIPTION 32 33This function sets up the program environment that libcurl needs. Think of it 34as an extension of the library loader. 35 36This function must be called at least once within a program (a program is all 37the code that shares a memory space) before the program calls any other 38function in libcurl. The environment it sets up is constant for the life of 39the program and is the same for every program, so multiple calls have the same 40effect as one call. 41 42The flags option is a bit pattern that tells libcurl exactly what features to 43init, as described below. Set the desired bits by ORing the values together. 44In normal operation, you must specify CURL_GLOBAL_ALL. Do not use any other 45value unless you are familiar with it and mean to control internal operations 46of libcurl. 47 48This function is thread-safe on most platforms. Then curl_version_info(3) has 49the `threadsafe` feature set (added in 7.84.0). 50 51If this is not thread-safe (the bit mentioned above is not set), you must not 52call this function when any other thread in the program (i.e. a thread sharing 53the same memory) is running. This does not just mean no other thread that is 54using libcurl. Because curl_global_init(3) calls functions of other libraries 55that are similarly thread unsafe, it could conflict with any other thread that 56uses these other libraries. 57 58If you are initializing libcurl from a Windows DLL you should not initialize 59it from *DllMain* or a static initializer because Windows holds the loader 60lock during that time and it could cause a deadlock. 61 62See the description in libcurl(3) of global environment requirements for 63details of how to use this function. 64 65# FLAGS 66 67## CURL_GLOBAL_ALL 68 69Initialize everything possible. This sets all known bits except 70**CURL_GLOBAL_ACK_EINTR**. 71 72## CURL_GLOBAL_SSL 73 74(This flag's presence or absence serves no meaning since 7.57.0. The 75description below is for older libcurl versions.) 76 77Initialize SSL. 78 79The implication here is that if this bit is not set, the initialization of the 80SSL layer needs to be done by the application or at least outside of 81libcurl. The exact procedure how to do SSL initialization depends on the TLS 82backend libcurl uses. 83 84Doing TLS based transfers without having the TLS layer initialized may lead to 85unexpected behaviors. 86 87## CURL_GLOBAL_WIN32 88 89Initialize the Win32 socket libraries. 90 91The implication here is that if this bit is not set, the initialization of 92Winsock has to be done by the application or you risk getting undefined 93behaviors. This option exists for when the initialization is handled outside 94of libcurl so there is no need for libcurl to do it again. 95 96## CURL_GLOBAL_NOTHING 97 98Initialize nothing extra. This sets no bit. 99 100## CURL_GLOBAL_DEFAULT 101 102A sensible default. It initializes both SSL and Win32. Right now, this equals 103the functionality of the **CURL_GLOBAL_ALL** mask. 104 105## CURL_GLOBAL_ACK_EINTR 106 107This bit has no point since 7.69.0 but its behavior is instead the default. 108 109Before 7.69.0: when this flag is set, curl acknowledges EINTR condition when 110connecting or when waiting for data. Otherwise, curl waits until full timeout 111elapses. (Added in 7.30.0) 112 113# %PROTOCOLS% 114 115# EXAMPLE 116 117~~~c 118int main(void) 119{ 120 curl_global_init(CURL_GLOBAL_DEFAULT); 121 122 /* use libcurl, then before exiting... */ 123 124 curl_global_cleanup(); 125} 126~~~ 127 128# %AVAILABILITY% 129 130# RETURN VALUE 131 132If this function returns non-zero, something went wrong and you cannot use the 133other curl functions. 134