summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-06-07 12:58:21 +0200
committerThomas Haller <thaller@redhat.com>2016-06-15 10:32:31 +0200
commite108f1cfafb2d3de1849b82b04e44c4f1251395e (patch)
tree88c20f190efee326e506feb0c8c96699cb1cdb07
parentccc1be34ee39731ee37f869fac8280971c69a17f (diff)
downloadNetworkManager-e108f1cfafb2d3de1849b82b04e44c4f1251395e.tar.gz
shared: add nm_strcmp_p() utils macro
-rw-r--r--shared/nm-macros-internal.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h
index 04e6a1ab6c..4622af9fd8 100644
--- a/shared/nm-macros-internal.h
+++ b/shared/nm-macros-internal.h
@@ -484,6 +484,36 @@ nm_strstrip (char *str)
return str ? g_strstrip (str) : NULL;
}
+/* g_ptr_array_sort()'s compare function takes pointers to the
+ * value. Thus, you cannot use strcmp directly. You can use
+ * nm_strcmp_p().
+ *
+ * Like strcmp(), this function is not forgiving to accept %NULL. */
+static inline int
+nm_strcmp_p (gconstpointer a, gconstpointer b)
+{
+ const char *s1 = *((const char **) a);
+ const char *s2 = *((const char **) b);
+
+ return strcmp (s1, s2);
+}
+
+/* like nm_strcmp_p(), suitable for g_ptr_array_sort_with_data().
+ * g_ptr_array_sort() just casts nm_strcmp_p() to a function of different
+ * signature. I guess, in glib there are knowledgeable people that ensure
+ * that this additional argument doesn't cause problems due to different ABI
+ * for every architecture that glib supports.
+ * For NetworkManager, we'd rather avoid such stunts.
+ **/
+static inline int
+nm_strcmp_p_with_data (gconstpointer a, gconstpointer b, gpointer user_data)
+{
+ const char *s1 = *((const char **) a);
+ const char *s2 = *((const char **) b);
+
+ return strcmp (s1, s2);
+}
+
/*****************************************************************************/
static inline guint