]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/search/sort/: QSORT(): Add macro
authorAlejandro Colomar <alx@kernel.org>
Thu, 14 Nov 2024 21:04:21 +0000 (22:04 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 24 Jan 2025 13:58:13 +0000 (07:58 -0600)
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/search/sort/qsort.c [new file with mode: 0644]
lib/search/sort/qsort.h [new file with mode: 0644]

index 3d3a96ae7b0c88a9152114ff04efe2ce00486e80..95db1053c9b1282b182f8fab4e4d79585d1366f2 100644 (file)
@@ -161,6 +161,8 @@ libshadow_la_SOURCES = \
        search/l/lfind.h \
        search/l/lsearch.c \
        search/l/lsearch.h \
+       search/sort/qsort.c \
+       search/sort/qsort.h \
        selinux.c \
        semanage.c \
        setugid.c \
diff --git a/lib/search/sort/qsort.c b/lib/search/sort/qsort.c
new file mode 100644 (file)
index 0000000..362d43d
--- /dev/null
@@ -0,0 +1,7 @@
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "search/sort/qsort.h"
diff --git a/lib/search/sort/qsort.h b/lib/search/sort/qsort.h
new file mode 100644 (file)
index 0000000..4a23506
--- /dev/null
@@ -0,0 +1,25 @@
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_SEARCH_SORT_QSORT_H_
+#define SHADOW_INCLUDE_LIB_SEARCH_SORT_QSORT_H_
+
+
+#include <config.h>
+
+#include <stdlib.h>
+
+#include "must_be.h"
+#include "search/cmp/cmp.h"
+
+
+#define QSORT(a, n)  do                                               \
+{                                                                     \
+       __auto_type  p_ = a;                                          \
+                                                                      \
+       qsort(p_, n, sizeof(*p_), CMP(typeof(p_)));                   \
+} while (0)
+
+
+#endif  // include guard