diff mbox

glib: add compatibility interface for g_strcmp0()

Message ID 1413457177-10132-1-git-send-email-arei.gonglei@huawei.com
State New
Headers show

Commit Message

Gonglei (Arei) Oct. 16, 2014, 10:59 a.m. UTC
From: Gonglei <arei.gonglei@huawei.com>

This patch fixes compilation errors when building against glib < 2.16.0
due to the missing g_strcmp0() function.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 Because g_strcmp0() was called in three places, I provide
 a back-compat implementation. 
---
 include/glib-compat.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Peter Maydell Oct. 17, 2014, 5:37 p.m. UTC | #1
On 16 October 2014 12:59,  <arei.gonglei@huawei.com> wrote:
> From: Gonglei <arei.gonglei@huawei.com>
>
> This patch fixes compilation errors when building against glib < 2.16.0
> due to the missing g_strcmp0() function.
>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  Because g_strcmp0() was called in three places, I provide
>  a back-compat implementation.

Applied to master, thanks.

-- PMM
diff mbox

Patch

diff --git a/include/glib-compat.h b/include/glib-compat.h
index e29bf69..f0615c9 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -45,6 +45,23 @@  static inline gint64 g_get_monotonic_time(void)
 }
 #endif
 
+#if !GLIB_CHECK_VERSION(2, 16, 0)
+static inline int g_strcmp0(const char *str1, const char *str2)
+{
+    int result;
+
+    if (!str1) {
+        result = -(str1 != str2);
+    } else if (!str2) {
+        result = (str1 != str2);
+    } else {
+        result = strcmp(str1, str2);
+    }
+
+    return result;
+}
+#endif
+
 #ifdef _WIN32
 /*
  * g_poll has a problem on Windows when using