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 <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/32085
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Julius Werner 2019-03-27 14:41:56 -07:00 committed by Patrick Georgi
parent f5b76fe9e9
commit 18c1b6b240
1 changed files with 15 additions and 2 deletions

View File

@ -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