/*-1* Copyright (c) 2021 M. Warner Losh <[email protected]>2*3* SPDX-License-Identifier: BSD-2-Clause4*/56/*7* A mostly Linux/glibc-compatible endian.h8*/910#ifndef _ENDIAN_H_11#define _ENDIAN_H_1213/*14* POSIX.1-2024 requires that endian.h define uint{16,32,64}_t. Although POSIX15* allows stdint.h symbols here, be conservative and only define there required16* ones. FreeBSD's sys/_endian.h doesn't need to expose those types since it17* implements all the [bl]eXtoh hto[bl]eX interfaces as macros calling builtin18* functions. POSIX.1-2024 allows functions, macros or both. We opt for macros19* only.20*/21#include <sys/_types.h>2223#ifndef _UINT16_T_DECLARED24typedef __uint16_t uint16_t;25#define _UINT16_T_DECLARED26#endif2728#ifndef _UINT32_T_DECLARED29typedef __uint32_t uint32_t;30#define _UINT32_T_DECLARED31#endif3233#ifndef _UINT64_T_DECLARED34typedef __uint64_t uint64_t;35#define _UINT64_T_DECLARED36#endif3738/*39* FreeBSD's sys/_endian.h is very close to the interface provided on Linux by40* glibc's endian.h as well as POSIX.1-2024's endian.h.41*/42#include <sys/_endian.h>4344/*45* glibc uses double underscore for these symbols. Define these unconditionally.46* The compiler defines __BYTE_ORDER__ these days, so we don't do anything47* with that since sys/endian.h defines _BYTE_ORDER based on it.48*/49#define __BIG_ENDIAN _BIG_ENDIAN50#define __BYTE_ORDER _BYTE_ORDER51#define __LITTLE_ENDIAN _LITTLE_ENDIAN52#define __PDP_ENDIAN _PDP_ENDIAN5354/*55* FreeBSD's sys/endian.h and machine/endian.h doesn't define a separate56* byte order for floats. Use the host non-float byte order.57*/58#define __FLOAT_WORD_ORDER _BYTE_ORDER5960/*61* We don't define BIG_ENDI, LITTLE_ENDI, HIGH_HALF and LOW_HALF macros that62* 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 to64* limit namespace visibility.65*/6667#endif /* _ENDIAN_H_ */686970