Browse Source

common: Move sorting functions to their own header file

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>
Simon Glass 4 years ago
parent
commit
8bef79bf3c
8 changed files with 40 additions and 5 deletions
  1. 1 0
      cmd/efi.c
  2. 1 0
      common/bootstage.c
  3. 1 0
      env/common.c
  4. 1 0
      fs/yaffs2/yaffs_qsort.c
  5. 0 5
      include/common.h
  6. 34 0
      include/sort.h
  7. 1 0
      lib/hashtable.c
  8. 1 0
      lib/qsort.c

+ 1 - 0
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",

+ 1 - 0
common/bootstage.c

@@ -11,6 +11,7 @@
 
 #include <common.h>
 #include <malloc.h>
+#include <sort.h>
 #include <spl.h>
 #include <linux/compiler.h>
 #include <linux/libfdt.h>

+ 1 - 0
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>

+ 1 - 0
fs/yaffs2/yaffs_qsort.c

@@ -5,6 +5,7 @@
  */
 
 #include "yportenv.h"
+#include <sort.h>
 /* #include <linux/string.h> */
 
 /*

+ 0 - 5
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>
 

+ 34 - 0
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

+ 1 - 0
lib/hashtable.c

@@ -14,6 +14,7 @@
 
 #include <errno.h>
 #include <malloc.h>
+#include <sort.h>
 
 #ifdef USE_HOSTCC		/* HOST build */
 # include <string.h>

+ 1 - 0
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,