Skip to content

Commit

Permalink
autoconf checks for htole64 and le64toh
Browse files Browse the repository at this point in the history
- addresses #52
  • Loading branch information
wookietreiber committed Sep 20, 2015
1 parent 8d318b9 commit 5d831e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_STRTOD
AC_CHECK_FUNCS([memchr memmove memset strerror strtol])
AC_CHECK_DECLS([htole64, le64toh],
[],
[
AC_CHECK_DECLS([htole64, le64toh], [], [], [#include <endian.h>])
],
[#include <sys/endian.h>])

AC_CONFIG_FILES([Makefile
src/Makefile
Expand Down
16 changes: 16 additions & 0 deletions src/endian.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ void xle64enc(uint8_t *d, uint64_t n) {
#include <sys/endian.h>
#endif

#if !HAVE_DECL_HTOLE64
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define htole64(x) (x)
# else
# define htole64(x) __bswap_64 (x)
# endif
#endif

#if !HAVE_DECL_LE64TOH
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define le64toh(x) (x)
# else
# define le64toh(x) __bswap_64 (x)
# endif
#endif

uint64_t xle64dec(const uint8_t *d) {
return le64toh(*(uint64_t*)d);
}
Expand Down

0 comments on commit 5d831e6

Please sign in to comment.