diff mbox series

[U-Boot,11/41] common: Move sorting functions to their own header file

Message ID 20190930144112.175618-12-sjg@chromium.org
State Changes Requested
Delegated to: Tom Rini
Headers show
Series common: Further reduce common.h | expand

Commit Message

Simon Glass Sept. 30, 2019, 2:40 p.m. UTC
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>
---

 cmd/efi.c               |  1 +
 common/bootstage.c      |  1 +
 env/common.c            |  1 +
 fs/yaffs2/yaffs_qsort.c |  1 +
 include/common.h        |  5 -----
 include/sort.h          | 34 ++++++++++++++++++++++++++++++++++
 lib/hashtable.c         |  1 +
 lib/qsort.c             |  1 +
 8 files changed, 40 insertions(+), 5 deletions(-)
 create mode 100644 include/sort.h
diff mbox series

Patch

diff --git a/cmd/efi.c b/cmd/efi.c
index 919cb2fcfd5..ea239a01f0b 100644
--- 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",
diff --git a/common/bootstage.c b/common/bootstage.c
index 56ef91ad859..d6744ee5bac 100644
--- a/common/bootstage.c
+++ b/common/bootstage.c
@@ -10,6 +10,7 @@ 
  */
 
 #include <common.h>
+#include <sort.h>
 #include <linux/libfdt.h>
 #include <malloc.h>
 #include <linux/compiler.h>
diff --git a/env/common.c b/env/common.c
index a23732bfd8b..d6c86a7e6e6 100644
--- a/env/common.c
+++ b/env/common.c
@@ -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>
diff --git a/fs/yaffs2/yaffs_qsort.c b/fs/yaffs2/yaffs_qsort.c
index b463569815d..32c767f3599 100644
--- a/fs/yaffs2/yaffs_qsort.c
+++ b/fs/yaffs2/yaffs_qsort.c
@@ -5,6 +5,7 @@ 
  */
 
 #include "yportenv.h"
+#include <sort.h>
 /* #include <linux/string.h> */
 
 /*
diff --git a/include/common.h b/include/common.h
index 97b661181b0..d17a2b2642c 100644
--- a/include/common.h
+++ b/include/common.h
@@ -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
index 00000000000..0c6b588fcb0
--- /dev/null
+++ b/include/sort.h
@@ -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
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 2caab0a4c6d..907e8a642f3 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -14,6 +14,7 @@ 
 
 #include <errno.h>
 #include <malloc.h>
+#include <sort.h>
 
 #ifdef USE_HOSTCC		/* HOST build */
 # include <string.h>
diff --git a/lib/qsort.c b/lib/qsort.c
index 57098841f9a..f63d4ef7268 100644
--- a/lib/qsort.c
+++ b/lib/qsort.c
@@ -18,6 +18,7 @@ 
 #include <linux/types.h>
 #include <common.h>
 #include <exports.h>
+#include <sort.h>
 
 void qsort(void  *base,
 	   size_t nel,