Skip to content

Commit 12a7c48

Browse files
committed
Cleanup endian.h patch for BSD-based systems
1 parent 477ef36 commit 12a7c48

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

Diff for: src/generic/endian.h

+22-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef ENDIAN_H
1010
#define ENDIAN_H
1111

12+
#include "config.h"
13+
1214
#if _WIN32
1315
#include <stdlib.h>
1416

@@ -49,13 +51,13 @@
4951
#elif __APPLE__
5052
#include <libkern/OSByteOrder.h>
5153

52-
#ifndef BYTE_ORDER
54+
#if !defined BYTE_ORDER
5355
# define BYTE_ORDER __BYTE_ORDER__
5456
#endif
55-
#ifndef LITTLE_ENDIAN
57+
#if !defined LITTLE_ENDIAN
5658
# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
5759
#endif
58-
#ifndef BIG_ENDIAN
60+
#if !defined BIG_ENDIAN
5961
# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
6062
#endif
6163

@@ -74,19 +76,27 @@
7476
#define le64toh(x) OSSwapLittleToHostInt64(x)
7577

7678
#else
77-
#include "config.h"
79+
#if HAVE_ENDIAN_H
80+
#include <endian.h>
81+
#elif defined(__OpenBSD__)
82+
// endian.h was added in OpenBSD 5.6. machine/endian.h exports optimized
83+
// bswap routines for use in sys/endian.h, which it includes.
84+
#include <machine/endian.h>
85+
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
86+
#include <sys/endian.h>
87+
#endif
7888

79-
#if defined(linux) || defined(__OpenBSD__)
80-
# ifdef HAVE_ENDIAN_H
81-
# include <endian.h> /* attempt to define endianness */
82-
# else
83-
# include <machine/endian.h> /* on older OpenBSD */
84-
# endif
89+
#if !defined BYTE_ORDER
90+
#error "missing definition of BYTE_ORDER"
8591
#endif
86-
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
87-
#include <sys/endian.h> /* attempt to define endianness */
92+
93+
#if !defined LITTLE_ENDIAN
94+
#error "missing definition of LITTLE_ENDIAN"
8895
#endif
8996

97+
#if !defined BIG_ENDIAN
98+
#error "missing definition of BIG_ENDIAN"
99+
#endif
90100
#endif
91101

92102
#endif // ENDIAN_H

0 commit comments

Comments
 (0)