+
+static void cleanup_curl(void)
+{
+#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H
+ curl_global_cleanup();
+#endif
+}
+
+static void initialize_curl_startup()
+{
+#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H
+ if (curl_global_init(CURL_GLOBAL_ALL))
+ {
+ fatal_message("curl_global_init(CURL_GLOBAL_ALL) failed");
+ }
+#endif
+
+ if (atexit(cleanup_curl))
+ {
+ fatal_message("atexit() failed");
+ }
+}
+
+static pthread_once_t start_key_once= PTHREAD_ONCE_INIT;
+void initialize_curl(void)
+{
+ int ret;
+ if ((ret= pthread_once(&start_key_once, initialize_curl_startup)) != 0)
+ {
+ fatal_message(strerror(ret));
+ }
+}
+