/*-1* Copyright (c) 2021 M. Warner Losh <[email protected]>2*3* SPDX-License-Identifier: BSD-2-Clause4*/56/*7* A mostly Linux/glibc-compatible byteswap.h8*/910#ifndef _BYTESWAP_H_11#define _BYTESWAP_H_1213/*14* sys/_endian.h brings in the shared interfaces between BSD's sys/endian.h, and15* glibc's endian.h. However, we need to include it here to get the16* __bswap{16,32,64} definitions that we use. sys/_endian.h has been consturcted to17* be compatible with including <endian.h>, <byteswap.h> or both in either order,18* as well as providing the BSD the bulk of sys/endian.h functionality.19*/20#include <sys/_endian.h>2122/*23* glibc's <byteswap.h> defines the bswap_* and __bswap_* macros below. Most24* software uses either just <sys/endian.h>, or both <endian.h> and25* <byteswap.h>. However, one can't define bswap16, etc in <endian.h> because26* several software packages will define them only when they detect <endian.h>27* is included (but not when sys/endian.h is included). Defining bswap16, etc28* here causes compilation errors for those packages. <endian.h> and29* <byteswap.h> need to be paired together, with the below defines here, for30* the highest level of glibc compatibility.31*/32#define __bswap_16(x) __bswap16(x)33#define __bswap_32(x) __bswap32(x)34#define __bswap_64(x) __bswap64(x)3536#define bswap_16(x) __bswap16(x)37#define bswap_32(x) __bswap32(x)38#define bswap_64(x) __bswap64(x)3940#endif /* _BYTESWAP_H_ */414243