From 1314d14c32713b448738cc821c04a5e7482bb4af Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 6 May 2024 09:10:46 -0600 Subject: [PATCH] endian.h: Define uint{16,32,64}_t The Draft Posix Issue 8 standard requires that these be defined. Define them in the usual way that lets multiple headers define them. Opted to not just use #include , allowed by the draft, to be conservative. Add notes about how we comply with Issue 8, and that we've opted to define these only as macros, though the standard allows functions, macros or both. Sponsored by: Netflix --- include/endian.h | 26 +++++++++++++++++++++++++- sys/sys/_endian.h | 6 ++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/endian.h b/include/endian.h index eb25cedf0bef..87ec7866c791 100644 --- a/include/endian.h +++ b/include/endian.h @@ -11,9 +11,33 @@ #ifndef _ENDIAN_H_ #define _ENDIAN_H_ +/* + * POSIX Issue 8 requires that endian.h define uint{16,32,64}_t. Although POSIX + * allows stdint.h symbols here, be conservative and only define there required + * ones. FreeBSD's sys/_endian.h doesn't need to expose those types since it + * implements all the [bl]eXtoh hto[bl]eX interfaces as macros calling builtin + * functions. POSIX allows functions, macros or both. We opt for macros only. + */ +#include + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _UINT64_T_DECLARED +typedef __uint64_t uint64_t; +#define _UINT64_T_DECLARED +#endif + /* * FreeBSD's sys/_endian.h is very close to the interface provided on Linux by - * glibc's endian.h. + * glibc's endian.h as well as POSIX Issue 8's endian.h. */ #include diff --git a/sys/sys/_endian.h b/sys/sys/_endian.h index 8d1eb3f3f3df..d0ffd87efa11 100644 --- a/sys/sys/_endian.h +++ b/sys/sys/_endian.h @@ -69,8 +69,10 @@ /* * POSIX Issue 8 will require these for endian.h. Define them there and in the - * traditional BSD compilation environment. Since issue 8 doesn't yet have an - * assigned date, use strictly greater than issue 7's date. + * traditional BSD compilation environment. PDP_ENDIAN isn't strictly in Issue + * 8, but is allowed as implementations can define any *_ENDIAN symbol. Since + * issue 8 doesn't yet have an assigned date, use strictly greater than issue + * 7's date. */ #if __BSD_VISIBLE || _POSIX_C_SOURCE > 200809 #define LITTLE_ENDIAN _LITTLE_ENDIAN