X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fglib-util.c;h=99f55f7aa8a91824fbb2d9202dc4fcc2fa1b9f3e;hb=3c4bb2012986d596b3ee0e65fac4b2c5b7b01540;hp=6320a1dea9e49549dcdb2850bae982e44b861f34;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/common-src/glib-util.c b/common-src/glib-util.c index 6320a1d..99f55f7 100644 --- a/common-src/glib-util.c +++ b/common-src/glib-util.c @@ -38,12 +38,8 @@ glib_init(void) { if (did_glib_init) return; did_glib_init = TRUE; - /* set up libcurl (this must happen before threading - * is initialized) */ + /* set up libcurl */ #ifdef HAVE_LIBCURL -# ifdef G_THREADS_ENABLED - g_assert(!g_thread_supported()); /* assert threads aren't initialized yet */ -# endif g_assert(curl_global_init(CURL_GLOBAL_ALL) == 0); #endif @@ -64,12 +60,6 @@ glib_init(void) { /* Initialize glib's type system. On glib >= 2.24, this will initialize * threads, so it must be done after curl is initialized. */ g_type_init(); - - /* And set up glib's threads */ -#if defined(G_THREADS_ENABLED) && !defined(G_THREADS_IMPL_NONE) - if (!g_thread_supported()) - g_thread_init(NULL); -#endif } typedef enum { @@ -106,38 +96,19 @@ GValue* g_value_unset_copy(const GValue * from, GValue * to) { return to; } -void g_list_free_full(GList * list) { - GList * cur = list; - - while (cur != NULL) { - gpointer data = cur->data; - amfree(data); - cur = g_list_next(cur); - } - - g_list_free(list); -} - -void g_slist_free_full(GSList * list) { +#if (GLIB_MAJOR_VERSION < 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 28)) +void slist_free_full(GSList * list, GDestroyNotify free_fn) { GSList * cur = list; while (cur != NULL) { gpointer data = cur->data; - amfree(data); + free_fn(data); cur = g_slist_next(cur); } g_slist_free(list); } - -void g_queue_free_full(GQueue * queue) { - while (!g_queue_is_empty(queue)) { - gpointer data; - data = g_queue_pop_head(queue); - amfree(data); - } - g_queue_free(queue); -} +#endif void g_ptr_array_free_full(GPtrArray * array) { size_t i; @@ -497,25 +468,36 @@ g_ptr_array_foreach (GPtrArray *array, #endif guint -g_str_case_hash( +g_str_amanda_hash( gconstpointer key) { /* modified version of glib's hash function, copyright * GLib Team and others 1997-2000. */ - const char *p = key; - guint h = g_ascii_toupper(*p); + const char *p; + guint h = 0; - if (h) - for (p += 1; *p != '\0'; p++) - h = (h << 5) - h + g_ascii_toupper(*p); + for (p = key; *p != '\0'; p++) + h = (h << 5) - h + (('_' == *p) ? '-' : g_ascii_tolower(*p)); return h; } gboolean -g_str_case_equal( +g_str_amanda_equal( gconstpointer v1, gconstpointer v2) { - return (0 == g_ascii_strcasecmp((char *)v1, (char *)v2)); + const gchar *p1 = v1, *p2 = v2; + while (*p1) { + /* letting '-' == '_' */ + if (!('-' == *p1 || '_' == *p1) || !('-' == *p2 || '_' == *p2)) + if (g_ascii_tolower(*p1) != g_ascii_tolower(*p2)) + return FALSE; + + p1++; + p2++; + } + + /* p1 is at '\0' is p2 too? */ + return *p2? FALSE : TRUE; }