Skip to content
Snippets Groups Projects
Commit fba15dc7 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa
Browse files

Use endian.h

parent 47fbcea5
Branches
No related merge requests found
......@@ -99,6 +99,8 @@ check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("stdlib.h" HAVE_STDLIB_H)
check_include_file("string.h" HAVE_STRING_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
check_include_file("endian.h" HAVE_ENDIAN_H)
include(CheckTypeSize)
# Checks for typedefs, structures, and compiler characteristics.
......@@ -110,6 +112,15 @@ if(SIZEOF_SSIZE_T STREQUAL "")
set(ssize_t int)
endif()
# Checks for symbols.
include(CheckSymbolExists)
if(HAVE_ENDIAN_H)
check_symbol_exists(be64toh "endian.h" HAVE_BE64TOH)
endif()
if(HAVE_SYS_ENDIAN_H)
check_symbol_exists(be64toh "sys/endian.h" HAVE_BE64TOH)
endif()
include(ExtractValidFlags)
set(WARNCFLAGS)
set(WARNCXXFLAGS)
......
......@@ -25,3 +25,12 @@
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1
/* Define to 1 if you have the <sys/endian.h> header file. */
#cmakedefine HAVE_SYS_ENDIAN_H 1
/* Define to 1 if you have the <endian.h> header file. */
#cmakedefine HAVE_ENDIAN_H 1
/* Define to 1 if you have the `be64toh' function. */
#cmakedefine HAVE_BE64TOH 1
......@@ -204,6 +204,8 @@ AC_CHECK_HEADERS([ \
stdlib.h \
string.h \
unistd.h \
sys/endian.h \
endian.h \
])
# Checks for typedefs, structures, and compiler characteristics.
......@@ -231,6 +233,16 @@ AC_CHECK_FUNCS([ \
memset \
])
# Checks for symbols.
AC_CHECK_DECLS([be64toh], [], [], [[
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#endif
]])
# More compiler flags from nghttp2.
save_CFLAGS=$CFLAGS
save_CXXFLAGS=$CXXFLAGS
......
......@@ -33,17 +33,25 @@
# include <arpa/inet.h>
#endif /* HAVE_ARPA_INET_H */
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif /* HAVE_ENDIAN_H */
#ifdef HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#endif /* HAVE_SYS_ENDIAN_H */
#include <ngtcp2/ngtcp2.h>
#ifdef WORDS_BIGENDIAN
# define ngtcp2_ntohl64(N) (N)
# define ngtcp2_htonl64(N) (N)
#else /* !WORDS_BIGENDIAN */
#if defined HAVE_BE64TOH || HAVE_DECL_BE64TOH
# define ngtcp2_ntohl64(N) be64toh(N)
# define ngtcp2_htonl64(N) htobe64(N)
#else /* !HAVE_BE64TOH */
# define ngtcp2_bswap64(N) \
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
# define ngtcp2_ntohl64(N) ngtcp2_bswap64(N)
# define ngtcp2_htonl64(N) ngtcp2_bswap64(N)
#endif /* !WORDS_BIGENDIAN */
#endif /* !HAVE_BE64TOH */
/*
* ngtcp2_get_uint64 reads 8 bytes from |p| as 64 bits unsigned
......
......@@ -92,9 +92,7 @@ static uint32_t hash(key_type key, uint32_t mod) {
uint8_t *p, *end;
uint32_t h = 0x811C9DC5u;
#ifndef WORDS_BIGENDIAN
key = ngtcp2_bswap64(key);
#endif /* !WORDS_BIGENDIAN */
key = ngtcp2_htonl64(key);
p = (uint8_t *)&key;
end = p + sizeof(key_type);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment