diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-10 06:07:21 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-10 06:07:21 +0000 |
| commit | 2f1f1297533922988e6080713df30e965fe6f16e (patch) | |
| tree | ffa9b67361b8cfc0687f3b4ee6714cc1b7d0c655 /util/nvmutil/nvmutil.c | |
| parent | 9747ca415125e3193e0df7a6bac1bbdab259379c (diff) | |
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 <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/nvmutil.c')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 20 |
1 files 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 <errno.h> #include <fcntl.h> +#include <limits.h> #include <stdarg.h> +#if defined(__has_include) +#if __has_include(<stdint.h>) #include <stdint.h> +#else +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#endif +#else +#include <stdint.h> +#endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#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 |
