File pacemaker-libcrmcommon-crm_alpha_sort.patch of Package pacemaker.10130

commit acfd99e383440fe1f415fb73eecfe8b47e66d691
Author: Ken Gaillot <kgaillot@redhat.com>
Date:   Fri Oct 13 17:08:48 2017 -0500

    Low: libcrmcommon: add function to sort list alphabetically

diff --git a/include/crm/common/internal.h b/include/crm/common/internal.h
index c587c5382..e5f34ec90 100644
--- a/include/crm/common/internal.h
+++ b/include/crm/common/internal.h
@@ -67,6 +67,7 @@ gboolean crm_ends_with_ext(const char *s, const char *match);
 char *add_list_element(char *list, const char *value);
 bool crm_compress_string(const char *data, int length, int max, char **result,
                          unsigned int *result_len);
+gint crm_alpha_sort(gconstpointer a, gconstpointer b);
 
 static inline int
 crm_strlen_zero(const char *s)
diff --git a/lib/common/strings.c b/lib/common/strings.c
index 573a14b19..6b3a7cf02 100644
--- a/lib/common/strings.c
+++ b/lib/common/strings.c
@@ -427,3 +427,27 @@ crm_compress_string(const char *data, int length, int max, char **result, unsign
     *result = compressed;
     return TRUE;
 }
+
+/*!
+ * \brief Compare two strings alphabetically (case-insensitive)
+ *
+ * \param[in] a  First string to compare
+ * \param[in] b  Second string to compare
+ *
+ * \return 0 if strings are equal, -1 if a < b, 1 if a > b
+ *
+ * \note Usable as a GCompareFunc with g_list_sort().
+ *       NULL is considered less than non-NULL.
+ */
+gint
+crm_alpha_sort(gconstpointer a, gconstpointer b)
+{
+    if (!a && !b) {
+        return 0;
+    } else if (!a) {
+        return -1;
+    } else if (!b) {
+        return 1;
+    }
+    return strcasecmp(a, b);
+}
openSUSE Build Service is sponsored by