aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2023-01-20 23:32:45 +0000
committerWarner Losh <imp@FreeBSD.org>2023-01-20 23:32:45 +0000
commit30e0d2a51026830e5141ce3dd43854819bba910c (patch)
tree8c2ba64dd48ecf556ecd4a9b0a8fdc3917465fc9 /include
parente8c1bd7257bf0ec1f2315376e707b2171000502e (diff)
Diffstat (limited to 'include')
-rw-r--r--include/Makefile4
-rw-r--r--include/endian.h43
2 files changed, 45 insertions, 2 deletions
diff --git a/include/Makefile b/include/Makefile
index 643451367b1b..aa4c115a3931 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -14,8 +14,8 @@ SUBDIR+= i386
SUBDIR_PARALLEL=
INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h _ctype.h ctype.h \
db.h \
- dirent.h dlfcn.h elf.h elf-hints.h err.h fmtmsg.h fnmatch.h fstab.h \
- fts.h ftw.h getopt.h glob.h grp.h \
+ dirent.h dlfcn.h elf.h elf-hints.h endian.h err.h fmtmsg.h fnmatch.h \
+ fstab.h fts.h ftw.h getopt.h glob.h grp.h \
ieeefp.h ifaddrs.h \
inttypes.h iso646.h kenv.h langinfo.h libgen.h limits.h link.h \
locale.h malloc.h malloc_np.h memory.h monetary.h mpool.h mqueue.h \
diff --git a/include/endian.h b/include/endian.h
new file mode 100644
index 000000000000..c7b78217cedd
--- /dev/null
+++ b/include/endian.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2021 M. Warner Losh <imp@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+/*
+ * A mostly Linux/glibc-compatible endian.h
+ */
+
+#ifndef _ENDIAN_H_
+#define _ENDIAN_H_
+
+/*
+ * FreeBSD's sys/_endian.h is very close to the interface provided on Linux by
+ * glibc's endian.h.
+ */
+#include <sys/_endian.h>
+
+/*
+ * glibc uses double underscore for these symbols. Define these unconditionally.
+ * The compiler defines __BYTE_ORDER__ these days, so we don't do anything
+ * with that since sys/endian.h defines _BYTE_ORDER based on it.
+ */
+#define __BIG_ENDIAN _BIG_ENDIAN
+#define __BYTE_ORDER _BYTE_ORDER
+#define __LITTLE_ENDIAN _LITTLE_ENDIAN
+#define __PDP_ENDIAN _PDP_ENDIAN
+
+/*
+ * FreeBSD's sys/endian.h and machine/endian.h doesn't define a separate
+ * byte order for floats. Use the host non-float byte order.
+ */
+#define __FLOAT_WORD_ORDER _BYTE_ORDER
+
+/*
+ * We don't define BIG_ENDI, LITTLE_ENDI, HIGH_HALF and LOW_HALF macros that
+ * glibc's endian.h defines since those appear to be internal to internal to
+ * glibc. We also don't try to emulate the various helper macros that glibc
+ * uses to limit namespace visibility.
+ */
+
+#endif /* _ENDIAN_H_ */