curl_global_init.3 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. .\" generated by cd2nroff 0.1 from curl_global_init.md
  2. .TH curl_global_init 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_global_init \- global libcurl initialization
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_global_init(long flags);
  9. .fi
  10. .SH DESCRIPTION
  11. This function sets up the program environment that libcurl needs. Think of it
  12. as an extension of the library loader.
  13. This function must be called at least once within a program (a program is all
  14. the code that shares a memory space) before the program calls any other
  15. function in libcurl. The environment it sets up is constant for the life of
  16. the program and is the same for every program, so multiple calls have the same
  17. effect as one call.
  18. The flags option is a bit pattern that tells libcurl exactly what features to
  19. init, as described below. Set the desired bits by ORing the values together.
  20. In normal operation, you must specify CURL_GLOBAL_ALL. Do not use any other
  21. value unless you are familiar with it and mean to control internal operations
  22. of libcurl.
  23. This function is thread\-safe on most platforms. Then \fIcurl_version_info(3)\fP has
  24. the \fIthreadsafe\fP feature set (added in 7.84.0).
  25. If this is not thread\-safe (the bit mentioned above is not set), you must not
  26. call this function when any other thread in the program (i.e. a thread sharing
  27. the same memory) is running. This does not just mean no other thread that is
  28. using libcurl. Because \fIcurl_global_init(3)\fP calls functions of other libraries
  29. that are similarly thread unsafe, it could conflict with any other thread that
  30. uses these other libraries.
  31. If you are initializing libcurl from a Windows DLL you should not initialize
  32. it from \fIDllMain\fP or a static initializer because Windows holds the loader
  33. lock during that time and it could cause a deadlock.
  34. See the description in \fIlibcurl(3)\fP of global environment requirements for
  35. details of how to use this function.
  36. .SH FLAGS
  37. .IP CURL_GLOBAL_ALL
  38. Initialize everything possible. This sets all known bits except
  39. \fBCURL_GLOBAL_ACK_EINTR\fP.
  40. .IP CURL_GLOBAL_SSL
  41. (This flag\(aqs presence or absence serves no meaning since 7.57.0. The
  42. description below is for older libcurl versions.)
  43. Initialize SSL.
  44. The implication here is that if this bit is not set, the initialization of the
  45. SSL layer needs to be done by the application or at least outside of
  46. libcurl. The exact procedure how to do SSL initialization depends on the TLS
  47. backend libcurl uses.
  48. Doing TLS based transfers without having the TLS layer initialized may lead to
  49. unexpected behaviors.
  50. .IP CURL_GLOBAL_WIN32
  51. Initialize the Win32 socket libraries.
  52. The implication here is that if this bit is not set, the initialization of
  53. winsock has to be done by the application or you risk getting undefined
  54. behaviors. This option exists for when the initialization is handled outside
  55. of libcurl so there is no need for libcurl to do it again.
  56. .IP CURL_GLOBAL_NOTHING
  57. Initialize nothing extra. This sets no bit.
  58. .IP CURL_GLOBAL_DEFAULT
  59. A sensible default. It initializes both SSL and Win32. Right now, this equals
  60. the functionality of the \fBCURL_GLOBAL_ALL\fP mask.
  61. .IP CURL_GLOBAL_ACK_EINTR
  62. This bit has no point since 7.69.0 but its behavior is instead the default.
  63. Before 7.69.0: when this flag is set, curl acknowledges EINTR condition when
  64. connecting or when waiting for data. Otherwise, curl waits until full timeout
  65. elapses. (Added in 7.30.0)
  66. .SH PROTOCOLS
  67. This functionality affects all supported protocols
  68. .SH EXAMPLE
  69. .nf
  70. int main(void)
  71. {
  72. curl_global_init(CURL_GLOBAL_DEFAULT);
  73. /* use libcurl, then before exiting... */
  74. curl_global_cleanup();
  75. }
  76. .fi
  77. .SH AVAILABILITY
  78. Added in curl 7.8
  79. .SH RETURN VALUE
  80. If this function returns non\-zero, something went wrong and you cannot use the
  81. other curl functions.
  82. .SH SEE ALSO
  83. .BR curl_easy_init (3),
  84. .BR curl_global_cleanup (3),
  85. .BR curl_global_init_mem (3),
  86. .BR curl_global_sslset (3),
  87. .BR curl_global_trace (3),
  88. .BR libcurl (3)