From 18c1b6b240b675c877b8bd731dfd58f5723d0c57 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 27 Mar 2019 14:41:56 -0700 Subject: libpayload: limits.h: Provide reliable definitions for all XXX_MAX/MIN Our current limits.h only provides (U)INT_MAX constants. This patch adds most others expected by POSIX. Since some of these may be different depending on architecture (e.g. 'long' is 32-bit on x86 and 64-bit on arm64), provide a definition that will automatically figure out the right value for the data model the compiler is using (as long as it's using two's complement for signed integers, which I think we can assume these days). Change-Id: I1124a41279abd4f53d208270e392e590ca8eaada Signed-off-by: Julius Werner Reviewed-on: https://review.coreboot.org/c/coreboot/+/32085 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- payloads/libpayload/include/limits.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'payloads/libpayload/include') diff --git a/payloads/libpayload/include/limits.h b/payloads/libpayload/include/limits.h index 2fecf239b0..4238e0e90b 100644 --- a/payloads/libpayload/include/limits.h +++ b/payloads/libpayload/include/limits.h @@ -40,7 +40,20 @@ # endif #endif -#define UINT_MAX (unsigned int)0xffffffff -#define INT_MAX (unsigned int)0x7fffffff +#define USHRT_MAX ((unsigned short int)~0U) +#define SHRT_MIN ((short int)(USHRT_MAX & ~(USHRT_MAX >> 1))) +#define SHRT_MAX ((short int)(USHRT_MAX >> 1)) + +#define UINT_MAX ((unsigned int)~0U) +#define INT_MIN ((int)(UINT_MAX & ~(UINT_MAX >> 1))) +#define INT_MAX ((int)(UINT_MAX >> 1)) + +#define ULONG_MAX ((unsigned long int)~0UL) +#define LONG_MIN ((long int)(ULONG_MAX & ~(ULONG_MAX >> 1))) +#define LONG_MAX ((long int)(ULONG_MAX >> 1)) + +#define ULLONG_MAX ((unsigned long long int)~0UL) +#define LLONG_MIN ((long long int)(ULLONG_MAX & ~(ULLONG_MAX >> 1))) +#define LLONG_MAX ((long long int)(ULLONG_MAX >> 1)) #endif -- cgit v1.2.3