]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/search/l/: LSEARCH(): Add macro
authorAlejandro Colomar <alx@kernel.org>
Thu, 14 Nov 2024 17:24:46 +0000 (18:24 +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/l/lsearch.c [new file with mode: 0644]
lib/search/l/lsearch.h [new file with mode: 0644]

index f34325a52c2746cd7c9dcb980a7bf8f0f64e695c..6ae24fb95b731f7a52357d9ff7b1888cd7a986f4 100644 (file)
@@ -159,6 +159,8 @@ libshadow_la_SOURCES = \
        search/cmp/cmp.h \
        search/l/lfind.c \
        search/l/lfind.h \
+       search/l/lsearch.c \
+       search/l/lsearch.h \
        selinux.c \
        semanage.c \
        setugid.c \
diff --git a/lib/search/l/lsearch.c b/lib/search/l/lsearch.c
new file mode 100644 (file)
index 0000000..0d790ce
--- /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/l/lsearch.h"
diff --git a/lib/search/l/lsearch.h b/lib/search/l/lsearch.h
new file mode 100644 (file)
index 0000000..fd269cb
--- /dev/null
@@ -0,0 +1,30 @@
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_SEARCH_L_LSEARCH_H_
+#define SHADOW_INCLUDE_LIB_SEARCH_L_LSEARCH_H_
+
+
+#include <config.h>
+
+#include <search.h>
+
+#include "must_be.h"
+#include "search/cmp/cmp.h"
+
+#include <assert.h>
+
+
+#define LSEARCH(k, a, n)                                              \
+({                                                                    \
+       __auto_type  k_ = k;                                          \
+       __auto_type  a_ = a;                                          \
+                                                                      \
+       static_assert(is_same_typeof(k_, a_), "");                    \
+                                                                      \
+       (typeof(k_)) lsearch(k_, a_, n, sizeof(*k_), CMP(typeof(k_)));\
+})
+
+
+#endif  // include guard