aboutsummaryrefslogtreecommitdiff
path: root/include/sort.h
diff options
context:
space:
mode:
authorSimon Glass2019-11-14 12:57:19 -0700
committerTom Rini2019-12-02 18:23:08 -0500
commit8bef79bf3c30cd1fc5367cc1f78f72e6552629e9 (patch)
tree318647c77cc039fd2a0e8d611c2156027a3c4691 /include/sort.h
parentf083583786913de7652312c137dd4fea5c2e291f (diff)
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>
Diffstat (limited to 'include/sort.h')
-rw-r--r--include/sort.h34
1 files changed, 34 insertions, 0 deletions
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