1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-25 06:04:04 +03:00

ldb: add NUMERIC_CMP macro to ldb.h

In other places we tend to include tsort.h, which also has TYPESAFE_QSORT.

ldb.h already has TYPESAFE_QSORT, so it might as well have NUMERIC_CMP.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15625

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit de1b94f79ea8694ecdddab4b455d539caa7e77e2)
This commit is contained in:
Douglas Bagnall 2024-04-03 17:53:39 +13:00 committed by Jule Anger
parent b46af17050
commit 9e19cc1711

View File

@ -2326,6 +2326,22 @@ do { \
} while (0)
#endif
#ifndef NUMERIC_CMP
/*
* NUMERIC_CMP is a safe replacement for `a - b` in comparison
* functions. It will work on integers, pointers, and floats.
*
* Rather than
*
* return a - b;
*
* use
*
* return NUMERIC_CMP(a, b);
*/
#define NUMERIC_CMP(a, b) (((a) > (b)) - ((a) < (b)))
#endif
/**