diff --git a/endian.h b/endian.h index fe2d6fc..0d178df 100644 --- a/endian.h +++ b/endian.h @@ -22,7 +22,9 @@ #if defined(__linux__) || defined(__CYGWIN__) -# include +# undef PORTABLE_ENDIAN_H__ +# include_next +# define PORTABLE_ENDIAN_H__ #elif defined(__APPLE__) @@ -48,11 +50,11 @@ # define __LITTLE_ENDIAN LITTLE_ENDIAN # define __PDP_ENDIAN PDP_ENDIAN -#elif defined(__OpenBSD__) +#elif defined(__OpenBSD__) || defined(__FreeBSD__) # include -#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__NetBSD__) || defined(__DragonFly__) # include @@ -72,19 +74,19 @@ # if BYTE_ORDER == LITTLE_ENDIAN -# define htobe16(x) htons(x) +# define htobe16(x) __builtin_bswap16(x) # define htole16(x) (x) -# define be16toh(x) ntohs(x) +# define be16toh(x) __builtin_bswap16(x) # define le16toh(x) (x) -# define htobe32(x) htonl(x) +# define htobe32(x) __builtin_bswap32(x) # define htole32(x) (x) -# define be32toh(x) ntohl(x) +# define be32toh(x) __builtin_bswap32(x) # define le32toh(x) (x) -# define htobe64(x) htonll(x) +# define htobe64(x) __builtin_bswap64(x) # define htole64(x) (x) -# define be64toh(x) ntohll(x) +# define be64toh(x) __builtin_bswap64(x) # define le64toh(x) (x) # elif BYTE_ORDER == BIG_ENDIAN