continue;
}
- LSEARCH(&grp->gr_gid, gids, &n);
+ LSEARCH(gid_t, &grp->gr_gid, gids, &n);
}
free(dup);
e = errno;
while (n > 1) {
- QSORT(addend, n);
+ QSORT(long, addend, n);
errno = 0;
addend[0] = addsl2(addend[0], addend[--n]);
-// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <stddef.h>
#include "search/cmp/cmp.h"
-#include "typetraits.h"
-#include <assert.h>
-
-#define LFIND(k, a, n) \
+#define LFIND(T, k, a, n) \
({ \
- __auto_type k_ = k; \
- __auto_type a_ = a; \
- \
- static_assert(is_same_typeof(k_, a_), ""); \
- \
- (typeof(k_)) lfind_(k_, a_, n, sizeof(*k_), CMP(typeof(k_))); \
+ _Generic(k, T *: 0, const T *: 0); \
+ _Generic(a, T *: 0, const T *: 0); \
+ (T *) lfind_(k, a, n, sizeof(T), CMP(T *)); \
})
-// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <search.h>
#include "search/cmp/cmp.h"
-#include "typetraits.h"
-#include <assert.h>
-
-#define LSEARCH(k, a, n) \
+#define LSEARCH(T, 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_)));\
+ _Generic(k, T *: 0, const T *: 0); \
+ _Generic(a, T *: 0); \
+ (T *) lsearch(k, a, n, sizeof(T), CMP(T *)); \
})
-// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <stdlib.h>
#include "search/cmp/cmp.h"
-#include "typetraits.h"
-#define QSORT(a, n) do \
+#define QSORT(T, a, n) do \
{ \
- __auto_type p_ = a; \
- \
- qsort(p_, n, sizeof(*p_), CMP(typeof(p_))); \
+ _Generic(a, T *: 0); \
+ qsort(a, n, sizeof(T), CMP(T *)); \
} while (0)
* database. However getgroups() will return the group. So
* if she is listed there already it is ok to grant membership.
*/
- is_member = (LFIND(&grp->gr_gid, gids, ngroups) != NULL);
+ is_member = (LFIND(gid_t, &grp->gr_gid, gids, ngroups) != NULL);
/*
* For split groups (due to limitations of NIS), check all
*/
gids = XREALLOC(gids, ngroups + 1, gid_t);
- LSEARCH(&gid, gids, &ngroups);
+ LSEARCH(gid_t, &gid, gids, &ngroups);
if (setgroups(ngroups, gids) == -1)
perror("setgroups");