Skip to content

Commit

Permalink
add endian.h for linux compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Oct 18, 2023
1 parent d4b8267 commit 57059da
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SUBDIR_PARALLEL=
INCS= a.out.h ar.h assert.h bitstring.h byteswap.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 \
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 \
Expand Down
43 changes: 43 additions & 0 deletions include/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*-
* Copyright (c) 2021 M. Warner Losh <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

/*
* A mostly Linux/glibc-compatible endian.h
*/

#ifndef _ENDIAN_H_
#define _ENDIAN_H_

/*
* BSD'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

/*
* BSD'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_ */

0 comments on commit 57059da

Please sign in to comment.