+#ifdef HAVE_LIBCURL
+#include <curl/curl.h>
+#endif
+
+void
+glib_init(void) {
+ static gboolean did_glib_init = FALSE;
+ if (did_glib_init) return;
+ did_glib_init = TRUE;
+
+ /* Initialize glib's type system */
+ g_type_init();
+
+ /* set up libcurl (this must happen before threading
+ * is initialized) */
+#ifdef HAVE_LIBCURL
+# ifdef G_THREADS_ENABLED
+ g_assert(!g_thread_supported());
+# endif
+ g_assert(curl_global_init(CURL_GLOBAL_ALL) == 0);
+#endif
+
+ /* And set up glib's threads */
+#if defined(G_THREADS_ENABLED) && !defined(G_THREADS_IMPL_NONE)
+ if (g_thread_supported()) {
+ return;
+ }
+ g_thread_init(NULL);
+#endif
+
+ /* do a version check */
+#if GLIB_CHECK_VERSION(2,6,0)
+ {
+ const char *glib_err = glib_check_version(GLIB_MAJOR_VERSION,
+ GLIB_MINOR_VERSION,
+ GLIB_MICRO_VERSION);
+ if (glib_err) {
+ error(_("%s: Amanda was compiled with glib-%d.%d.%d"), glib_err,
+ GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
+ exit(1); /* glib_init may be called before error handling is set up */
+ }
+ }
+#endif
+}
+