Skip to content

Commit 384ff64

Browse files
committed
portable_endian.h: A more uniform fix for the various BSD flavours
See pull requests #59 and #83. It looks like various BSD derivates have adopted the more common naming conventions for the endian conversion macros, which means that we would attempt to redefine them without need (potentially even to 'historic' names that no longer exist). Try to avoid this by properly checking for existing functions first. Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
1 parent 4c41110 commit 384ff64

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

include/portable_endian.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,29 @@
4141
# define __LITTLE_ENDIAN LITTLE_ENDIAN
4242
# define __PDP_ENDIAN PDP_ENDIAN
4343

44-
#elif defined(__OpenBSD__) || defined(__FreeBSD__)
45-
46-
# include <sys/endian.h>
47-
48-
#elif defined(__NetBSD__) || defined(__DragonFly__)
44+
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
4945

5046
# include <sys/endian.h>
5147

48+
/* For functions still missing, try to substitute 'historic' OpenBSD names */
49+
#ifndef be16toh
5250
# define be16toh(x) betoh16(x)
51+
#endif
52+
#ifndef le16toh
5353
# define le16toh(x) letoh16(x)
54-
54+
#endif
55+
#ifndef be32toh
5556
# define be32toh(x) betoh32(x)
57+
#endif
58+
#ifndef le32toh
5659
# define le32toh(x) letoh32(x)
57-
60+
#endif
61+
#ifndef be64toh
5862
# define be64toh(x) betoh64(x)
63+
#endif
64+
#ifndef le64toh
5965
# define le64toh(x) letoh64(x)
66+
#endif
6067

6168
#elif defined(__WINDOWS__)
6269

0 commit comments

Comments
 (0)