X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fglib-util.c;fp=common-src%2Fglib-util.c;h=dd6b38e0e12397d01856a4be924171eb267cbf74;hb=2627875b7d18858bc1f9f7652811e4d8c15a23eb;hp=ec9728ad4c8a24d7ad2a61f52bb3b0a789a8a007;hpb=fb2bd066c2f8b34addafe48d62550e3033a59431;p=debian%2Famanda diff --git a/common-src/glib-util.c b/common-src/glib-util.c index ec9728a..dd6b38e 100644 --- a/common-src/glib-util.c +++ b/common-src/glib-util.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005 Zmanda, Inc. All Rights Reserved. + * Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved. * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 2.1 as @@ -14,8 +14,8 @@ * along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120 - * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com + * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300 + * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com */ /* @@ -28,6 +28,51 @@ #include "glib-util.h" #include "conffile.h" /* For find_multiplier. */ +#ifdef HAVE_LIBCURL +#include +#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 +} + typedef enum { FLAG_STRING_NAME, FLAG_STRING_SHORT_NAME, @@ -402,6 +447,10 @@ char * g_english_strjoinv(char ** strv, const char * conjunction) { strv = g_strdupv(strv); length = g_strv_length(strv); + + if (length == 1) + return stralloc(strv[0]); + last = strv[length - 1]; strv[length - 1] = NULL; @@ -433,5 +482,43 @@ guint g_strv_length(gchar ** strv) { } return rval; } - #endif /* GLIB_CHECK_VERSION(2.6.0) */ + +#if !GLIB_CHECK_VERSION(2,4,0) +void +g_ptr_array_foreach (GPtrArray *array, + GFunc func, + gpointer user_data) +{ + guint i; + + g_return_if_fail (array); + + for (i = 0; i < array->len; i++) + (*func) (array->pdata[i], user_data); +} +#endif + +guint +g_str_case_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); + + if (h) + for (p += 1; *p != '\0'; p++) + h = (h << 5) - h + g_ascii_toupper(*p); + + return h; +} + +gboolean +g_str_case_equal( + gconstpointer v1, + gconstpointer v2) +{ + return (0 == g_ascii_strcasecmp((char *)v1, (char *)v2)); +}