xref: /freebsd/include/endian.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /*-
2  * Copyright (c) 2021 M. Warner Losh <imp@FreeBSD.org>
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  */
6 
7 /*
8  * A mostly Linux/glibc-compatible endian.h
9  */
10 
11 #ifndef _ENDIAN_H_
12 #define _ENDIAN_H_
13 
14 /*
15  * FreeBSD's sys/_endian.h is very close to the interface provided on Linux by
16  * glibc's endian.h.
17  */
18 #include <sys/_endian.h>
19 
20 /*
21  * glibc uses double underscore for these symbols. Define these unconditionally.
22  * The compiler defines __BYTE_ORDER__ these days, so we don't do anything
23  * with that since sys/endian.h defines _BYTE_ORDER based on it.
24  */
25 #define __BIG_ENDIAN		_BIG_ENDIAN
26 #define __BYTE_ORDER		_BYTE_ORDER
27 #define __LITTLE_ENDIAN		_LITTLE_ENDIAN
28 #define __PDP_ENDIAN		_PDP_ENDIAN
29 
30 /*
31  * FreeBSD's sys/endian.h and machine/endian.h doesn't define a separate
32  * byte order for floats. Use the host non-float byte order.
33  */
34 #define __FLOAT_WORD_ORDER	_BYTE_ORDER
35 
36 /*
37  * We don't define BIG_ENDI, LITTLE_ENDI, HIGH_HALF and LOW_HALF macros that
38  * glibc's endian.h defines since those appear to be internal to glibc.
39  * We also don't try to emulate the various helper macros that glibc uses to
40  * limit namespace visibility.
41  */
42 
43 #endif /* _ENDIAN_H_ */
44