2 * Copyright (c) 2021 M. Warner Losh <imp@FreeBSD.org>
4 * SPDX-License-Identifier: BSD-2-Clause
8 * A mostly Linux/glibc-compatible endian.h
15 * POSIX Issue 8 requires that endian.h define uint{16,32,64}_t. Although POSIX
16 * allows stdint.h symbols here, be conservative and only define there required
17 * ones. FreeBSD's sys/_endian.h doesn't need to expose those types since it
18 * implements all the [bl]eXtoh hto[bl]eX interfaces as macros calling builtin
19 * functions. POSIX allows functions, macros or both. We opt for macros only.
21 #include <sys/_types.h>
23 #ifndef _UINT16_T_DECLARED
24 typedef __uint16_t uint16_t;
25 #define _UINT16_T_DECLARED
28 #ifndef _UINT32_T_DECLARED
29 typedef __uint32_t uint32_t;
30 #define _UINT32_T_DECLARED
33 #ifndef _UINT64_T_DECLARED
34 typedef __uint64_t uint64_t;
35 #define _UINT64_T_DECLARED
39 * FreeBSD's sys/_endian.h is very close to the interface provided on Linux by
40 * glibc's endian.h as well as POSIX Issue 8's endian.h.
42 #include <sys/_endian.h>
45 * glibc uses double underscore for these symbols. Define these unconditionally.
46 * The compiler defines __BYTE_ORDER__ these days, so we don't do anything
47 * with that since sys/endian.h defines _BYTE_ORDER based on it.
49 #define __BIG_ENDIAN _BIG_ENDIAN
50 #define __BYTE_ORDER _BYTE_ORDER
51 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
52 #define __PDP_ENDIAN _PDP_ENDIAN
55 * FreeBSD's sys/endian.h and machine/endian.h doesn't define a separate
56 * byte order for floats. Use the host non-float byte order.
58 #define __FLOAT_WORD_ORDER _BYTE_ORDER
61 * We don't define BIG_ENDI, LITTLE_ENDI, HIGH_HALF and LOW_HALF macros that
62 * glibc's endian.h defines since those appear to be internal to glibc.
63 * We also don't try to emulate the various helper macros that glibc uses to
64 * limit namespace visibility.
67 #endif /* _ENDIAN_H_ */