The branch main has been updated by ngie: URL: https://cgit.FreeBSD.org/src/commit/?id=db5344a7445f1a796bc3cacd32a46e88e3e589a7
commit db5344a7445f1a796bc3cacd32a46e88e3e589a7 Author: Enji Cooper <[email protected]> AuthorDate: 2026-02-26 02:29:49 +0000 Commit: Enji Cooper <[email protected]> CommitDate: 2026-02-26 07:41:08 +0000 lib/libnetbsd: bring in `__type_m{ax,in}*` macro family These macros are used by some of the NetBSD tests which calculate the size of types, e.g., `__type_max(time_t)`. This wraps up the set of macros needed in order to update to the a netbsd-tests snapshot from this past month. Obtained from: https://github.com/netbsd/src (55b4b44) MFC after: 1 week --- lib/libnetbsd/sys/cdefs.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/libnetbsd/sys/cdefs.h b/lib/libnetbsd/sys/cdefs.h index 78c80735ad01..e4ff4a516519 100644 --- a/lib/libnetbsd/sys/cdefs.h +++ b/lib/libnetbsd/sys/cdefs.h @@ -110,4 +110,34 @@ */ #define __nothing (/*LINTED*/(void)0) +#define __negative_p(x) (!((x) > 0) && ((x) != 0)) + +#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * __CHAR_BIT__ - 1)))) +#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * __CHAR_BIT__ - 1)))) +#define __type_min_u(t) ((t)0ULL) +#define __type_max_u(t) ((t)~0ULL) +#define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) +#define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) +#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) + + +#define __type_fit_u(t, a) \ + (/*LINTED*/!__negative_p(a) && \ + ((__UINTMAX_TYPE__)((a) + __zeroull()) <= \ + (__UINTMAX_TYPE__)__type_max_u(t))) + +#define __type_fit_s(t, a) \ + (/*LINTED*/__negative_p(a) \ + ? ((__INTMAX_TYPE__)((a) + __zeroll()) >= \ + (__INTMAX_TYPE__)__type_min_s(t)) \ + : ((__INTMAX_TYPE__)((a) + __zeroll()) >= (__INTMAX_TYPE__)0 && \ + ((__INTMAX_TYPE__)((a) + __zeroll()) <= \ + (__INTMAX_TYPE__)__type_max_s(t)))) + +/* + * return true if value 'a' fits in type 't' + */ +#define __type_fit(t, a) (__type_is_signed(t) ? \ + __type_fit_s(t, a) : __type_fit_u(t, a)) + #endif /* _LIBNETBSD_SYS_CDEFS_H_ */
