From 2f1f1297533922988e6080713df30e965fe6f16e Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Tue, 10 Mar 2026 06:07:21 +0000 Subject: util/nvmutil: add portable asserts for integers we need this to be the case for our code, that char and uint8_t are 8 bits, and that uint16_t and uint32_t are 16- and 32-bit. these asserts protect us in case it's not (it will cause a compile time error). Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 160981ad..79e7013b 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -31,18 +31,28 @@ #include #include +#include #include +#if defined(__has_include) +#if __has_include() #include +#else +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#endif +#else +#include +#endif #include #include #include #include -#if __STDC_VERSION__ >= 201112L -_Static_assert(sizeof(uint16_t) == 2, "uint16_t must be 16 bits"); -#else -typedef char static_assert_uint16_t_is_2[(sizeof(uint16_t) == 2) ? 1 : -1]; -#endif +typedef char static_assert_char_is_8_bits[(CHAR_BIT == 8) ? 1 : -1]; +typedef char static_assert_uint8_is_1[(sizeof(uint8_t) == 1) ? 1 : -1]; +typedef char static_assert_uint16_is_2[(sizeof(uint16_t) == 2) ? 1 : -1]; +typedef char static_assert_uint32_is_4[(sizeof(uint32_t) == 4) ? 1 : -1]; /* * The BSD versions that could realistically build -- cgit v1.2.1