diff options
-rw-r--r-- | epan/strutil.c | 29 | ||||
-rw-r--r-- | epan/strutil.h | 8 | ||||
-rw-r--r-- | fileset.c | 1 |
3 files changed, 38 insertions, 0 deletions
diff --git a/epan/strutil.c b/epan/strutil.c index fa6b6aa0e4..1e1c12b4df 100644 --- a/epan/strutil.c +++ b/epan/strutil.c @@ -1084,3 +1084,32 @@ gchar *string_replace(const gchar* str, const gchar *old_val, const gchar *new_v return new_str; } + + +/** + * g_strcmp0 appears first in GLIB 2.16, define it locally for earlier versions. + * Copied from gtestutils.c in glib + * g_strcmp0: + * @str1: (allow-none): a C string or %NULL + * @str2: (allow-none): another C string or %NULL + * + * Compares @str1 and @str2 like strcmp(). Handles %NULL + * gracefully by sorting it before non-%NULL strings. + * Comparing two %NULL pointers returns 0. + * + * Returns: -1, 0 or 1, if @str1 is <, == or > than @str2. + * + * Since: 2.16 + */ +#if !GLIB_CHECK_VERSION(2,16,0) +int +g_strcmp0 (const char *str1, + const char *str2) +{ + if (!str1) + return -(str1 != str2); + if (!str2) + return str1 != str2; + return strcmp (str1, str2); +} +#endif /* GLIB_CHECK_VERSION(2,16,0) */ diff --git a/epan/strutil.h b/epan/strutil.h index 2cc8b80d7b..f64316ed86 100644 --- a/epan/strutil.h +++ b/epan/strutil.h @@ -272,6 +272,14 @@ gchar* ws_strdup_unescape_char (const gchar *str, const gchar chr); */ gchar *string_replace(const gchar* str, const gchar *old_val, const gchar *new_val); +/** + * g_strcmp0 appears first in GLIB 2.16, define it locally for earlier versions. + */ + +#if !GLIB_CHECK_VERSION(2,16,0) +int g_strcmp0 (const char *str1, + const char *str2); +#endif /* GLIB_CHECK_VERSION(2,16,0) */ #ifdef __cplusplus } #endif /* __cplusplus */ @@ -54,6 +54,7 @@ #include "globals.h" #include <epan/filesystem.h> +#include <epan/strutil.h> #include "fileset.h" |