git: 1314d14c3271 - main - endian.h: Define uint{16,32,64}_t
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 06 May 2024 16:44:09 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=1314d14c32713b448738cc821c04a5e7482bb4af commit 1314d14c32713b448738cc821c04a5e7482bb4af Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2024-05-06 15:10:46 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2024-05-06 16:43:14 +0000 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 <stdint.h>, 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 <sys/_types.h> + +#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 <sys/_endian.h> 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