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 16--- 17 18# NAME 19 20curl_global_init - Global libcurl initialization 21 22# SYNOPSIS 23 24~~~c 25#include <curl/curl.h> 26 27CURLcode curl_global_init(long flags); 28~~~ 29 30# DESCRIPTION 31 32This function sets up the program environment that libcurl needs. Think of it 33as an extension of the library loader. 34 35This function must be called at least once within a program (a program is all 36the code that shares a memory space) before the program calls any other 37function in libcurl. The environment it sets up is constant for the life of 38the program and is the same for every program, so multiple calls have the same 39effect as one call. 40 41The flags option is a bit pattern that tells libcurl exactly what features to 42init, as described below. Set the desired bits by ORing the values together. 43In normal operation, you must specify CURL_GLOBAL_ALL. Do not use any other 44value unless you are familiar with it and mean to control internal operations 45of libcurl. 46 47This function is thread-safe since libcurl 7.84.0 if 48curl_version_info(3) has the CURL_VERSION_THREADSAFE feature bit set 49(most platforms). 50 51If this is not thread-safe, you must not call this function when any other 52thread in the program (i.e. a thread sharing the same memory) is running. 53This does not just mean no other thread that is using libcurl. Because 54curl_global_init(3) calls functions of other libraries that are 55similarly thread unsafe, it could conflict with any other thread that uses 56these 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# EXAMPLE 114 115~~~c 116int main(void) 117{ 118 curl_global_init(CURL_GLOBAL_DEFAULT); 119 120 /* use libcurl, then before exiting... */ 121 122 curl_global_cleanup(); 123} 124~~~ 125 126# AVAILABILITY 127 128Added in 7.8 129 130# RETURN VALUE 131 132If this function returns non-zero, something went wrong and you cannot use the 133other curl functions. 134