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