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

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

Index: pacemaker/include/crm_internal.h
===================================================================
--- pacemaker.orig/include/crm_internal.h
+++ pacemaker/include/crm_internal.h
@@ -208,6 +208,7 @@ char *generate_hash_key(const char *crm_
 
 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);
 
 /*! remote tcp/tls helper functions */
 typedef struct crm_remote_s crm_remote_t;
Index: pacemaker/lib/common/utils.c
===================================================================
--- pacemaker.orig/lib/common/utils.c
+++ pacemaker/lib/common/utils.c
@@ -2513,3 +2513,27 @@ crm_parse_agent_spec(const char *spec, c
     *type = strdup(spec);
     return pcmk_ok;
 }
+
+/*!
+ * \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