]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
add grub_qsort_strcmp to use when sorting array of strings
authorAndrey Borzenkov <arvidjaar@gmail.com>
Sat, 7 Dec 2013 10:29:00 +0000 (14:29 +0400)
committerAndrey Borzenkov <arvidjaar@gmail.com>
Sat, 7 Dec 2013 10:29:00 +0000 (14:29 +0400)
Compare function used in qsort gets arguments by reference, so strcmp
cannot be used directly - it expects pointer to char, but gets pointer
to pointer to char.

Introduce new helper grub_qsort_strcmp and use it in grub-install.
This helper is going to be used in a couple more places as well so
add it to global file, not in grub-install.c.

ChangeLog
include/grub/util/misc.h
util/grub-install.c
util/misc.c

index aa1c7a07696c7a3cbf329bc3c8536703608e7615..ee27fccd8f378ed02710063b59507c5504d31772 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-12-07  Andrey Borzenkov <arvidjaar@gmail.com>
+
+       * util/misc.c (grub_qsort_strcmp): Add qsort helper function to sort
+       strings.
+       * include/grub/util/misc.h: Define it ...
+       * util/grub-install.c (device_map_check_duplicates): ... and use it.
+
 2013-12-07  Andrey Borzenkov <arvidjaar@gmail.com>
 
        * util/grub.d/30_os-prober.in: Fix use of grub-probe instead of
index 6aacf237ab79b057628ddbc659936c2c8ef7e6f3..192874d42b9d11ab85e6f48586a5807b18a19c6f 100644 (file)
@@ -47,4 +47,6 @@ void grub_util_init_nls (void);
 
 void grub_util_host_init (int *argc, char ***argv);
 
+int grub_qsort_strcmp (const void *, const void *);
+
 #endif /* ! GRUB_UTIL_MISC_HEADER */
index 7a1db422b449674c2ce5e5292b03bde3d705d461..db5e0c321346b613888039f958984c2aebdb980f 100644 (file)
@@ -586,7 +586,7 @@ device_map_check_duplicates (const char *dev_map)
 
   fclose (fp);
 
-  qsort (d, filled, sizeof (d[0]), (int (*) (const void *, const void *))strcmp);
+  qsort (d, filled, sizeof (d[0]), grub_qsort_strcmp);
 
   for (i = 0; i + 1 < filled; i++)
     if (strcmp (d[i], d[i+1]) == 0)
index 0de340bbe36dd341778a24dfc861356f806817c0..9eb1fc13cef3fa81760c862ccb827c1d02f16738 100644 (file)
@@ -256,3 +256,11 @@ void
 grub_register_exported_symbols (void)
 {
 }
+
+/* Used in comparison of arrays of strings with qsort */
+int
+grub_qsort_strcmp (const void *p1, const void *p2)
+{
+  return strcmp(*(char **)p1, *(char **)p2);
+}
+