/
niceSOFT
/
shadow
Обзор
Документация
Войти
/
niceSOFT
/
shadow
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/search/cmp/cmp.h
86 строк
2 KB
Alejandro Colomar
lib/: Use non-empty compound literals
30 дек 2025, 19:07
30 дек 2025, 19:07
9214a8e
Код
Авторство
О чём код?
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org> // SPDX-License-Identifier: BSD-3-Clause #ifndef SHADOW_INCLUDE_LIB_SEARCH_CMP_CMP_H_ #define SHADOW_INCLUDE_LIB_SEARCH_CMP_CMP_H_ #include "config.h" #define CMP(T) \ ( \ _Generic((T){0}, \ int: cmp_int, \ long: cmp_long, \ unsigned int: cmp_uint, \ unsigned long: cmp_ulong \ ) \ ) /* Compatible with bsearch(3), lfind(3), and qsort(3). */ inline int cmp_int(const void *key, const void *elt); inline int cmp_long(const void *key, const void *elt); inline int cmp_uint(const void *key, const void *elt); inline int cmp_ulong(const void *key, const void *elt); inline int cmp_int(const void *key, const void *elt) { const int *k = key; const int *e = elt; if (*k < *e) return -1; if (*k > *e) return +1; return 0; } inline int cmp_long(const void *key, const void *elt) { const long *k = key; const long *e = elt; if (*k < *e) return -1; if (*k > *e) return +1; return 0; } inline int cmp_uint(const void *key, const void *elt) { const unsigned int *k = key; const unsigned int *e = elt; if (*k < *e) return -1; if (*k > *e) return +1; return 0; } inline int cmp_ulong(const void *key, const void *elt) { const unsigned long *k = key; const unsigned long *e = elt; if (*k < *e) return -1; if (*k > *e) return +1; return 0; } #endif // include guard