common: Move sorting functions to their own header file
authorSimon Glass <sjg@chromium.org>
Thu, 14 Nov 2019 19:57:19 +0000 (12:57 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 2 Dec 2019 23:23:08 +0000 (18:23 -0500)
These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
cmd/efi.c
common/bootstage.c
env/common.c
fs/yaffs2/yaffs_qsort.c
include/common.h
include/sort.h [new file with mode: 0644]
lib/hashtable.c
lib/qsort.c

index 919cb2fcfd55a8b1d063cf610ad120b253f04fc1..ea239a01f0b1c38e187b22d57a6f7695d36881ef 100644 (file)
--- a/cmd/efi.c
+++ b/cmd/efi.c
@@ -9,6 +9,7 @@
 #include <efi.h>
 #include <errno.h>
 #include <malloc.h>
+#include <sort.h>
 
 static const char *const type_name[] = {
        "reserved",
index e8b7bbf81a6d1b30feaf6d7986f9603f82932671..79972e46f29f22f0cc2201d28934aae8c58c4b00 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <common.h>
 #include <malloc.h>
+#include <sort.h>
 #include <spl.h>
 #include <linux/compiler.h>
 #include <linux/libfdt.h>
index 0edb6fb04c254543db34a3e014843d240d0529fb..1fd1bd01d3bb159aa1c4bcad1d317996b658231b 100644 (file)
@@ -11,6 +11,7 @@
 #include <command.h>
 #include <env.h>
 #include <env_internal.h>
+#include <sort.h>
 #include <linux/stddef.h>
 #include <search.h>
 #include <errno.h>
index b463569815d514e22f3619c59b4c12717c4b2d4e..32c767f3599f1a018a5453e4234cac2f5062592c 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "yportenv.h"
+#include <sort.h>
 /* #include <linux/string.h> */
 
 /*
index 97b661181b0c7ead9c415cd52d7797526627b228..d17a2b2642c941251cdb89a2405778b35eb01fe8 100644 (file)
@@ -304,11 +304,6 @@ ulong      ticks2usec    (unsigned long ticks);
 /* lib/lz4_wrapper.c */
 int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
 
-/* lib/qsort.c */
-void qsort(void *base, size_t nmemb, size_t size,
-          int(*compar)(const void *, const void *));
-int strcmp_compar(const void *, const void *);
-
 /* lib/uuid.c */
 #include <uuid.h>
 
diff --git a/include/sort.h b/include/sort.h
new file mode 100644 (file)
index 0000000..0c6b588
--- /dev/null
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#ifndef __SORT_H
+#define __SORT_H
+
+/**
+ * qsort() - Use the quicksort algorithm to sort some values
+ *
+ * @base: Base address of array to sort
+ * @nmemb: Number of members to sort
+ * @size: Size of each member in bytes
+ * @compar: Comparison function which should return:
+ *     < 0 if element at s1 < element at s2,
+ *       0 if element at s1 == element at s2,
+ *     > 0 if element at s1 > element at s2,
+ */
+void qsort(void *base, size_t nmemb, size_t size,
+          int (*compar)(const void *s1, const void *s2));
+
+/**
+ * strcmp_compar() - compar function for string arrays
+ *
+ * This can be passed to qsort when a string array is being sorted
+ *
+ * @s1: First string to compare
+ * @s2: Second string to compare
+ * @return comparison value (less than, equal to, or greater than 0)
+ */
+int strcmp_compar(const void *s1, const void *s2);
+
+#endif
index 2caab0a4c6d3157d3de8d83757bacfa00e257265..907e8a642f37e4b4871a949fb32ce5dd97623e90 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <errno.h>
 #include <malloc.h>
+#include <sort.h>
 
 #ifdef USE_HOSTCC              /* HOST build */
 # include <string.h>
index 57098841f9a40ff9bd590075845ca6b9b06f8a9a..f63d4ef726841cd8e51c76988007db9e53a9ed16 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/types.h>
 #include <common.h>
 #include <exports.h>
+#include <sort.h>
 
 void qsort(void  *base,
           size_t nel,