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
This commit is contained in:
@@ -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_ */
|
||||
|
||||
Reference in New Issue
Block a user