From: Alejandro Colomar Date: Thu, 14 Nov 2024 17:24:46 +0000 (+0100) Subject: lib/search/l/: LSEARCH(): Add macro X-Git-Tag: 4.17.3~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=031486fcc0b01c46809235ab2b10b908a05c0b09;p=thirdparty%2Fshadow.git lib/search/l/: LSEARCH(): Add macro Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index f34325a52..6ae24fb95 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 index 000000000..0d790cec8 --- /dev/null +++ b/lib/search/l/lsearch.c @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "search/l/lsearch.h" diff --git a/lib/search/l/lsearch.h b/lib/search/l/lsearch.h new file mode 100644 index 000000000..fd269cb5e --- /dev/null +++ b/lib/search/l/lsearch.h @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SEARCH_L_LSEARCH_H_ +#define SHADOW_INCLUDE_LIB_SEARCH_L_LSEARCH_H_ + + +#include + +#include + +#include "must_be.h" +#include "search/cmp/cmp.h" + +#include + + +#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