From 14b09f54a63ae08dda87f469d10539885d566f15 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 13 Oct 2020 22:20:46 +0200 Subject: [PATCH] check endianess --- CMake/_Include.cmake | 3 +++ example/byteorder.cc | 4 ++-- src/libhashkit/jenkins.cc | 8 ++++---- src/libmemcached/byteorder.cc | 4 ++-- src/mem_config.h.in | 3 ++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CMake/_Include.cmake b/CMake/_Include.cmake index 67fe16bf..7067ef46 100644 --- a/CMake/_Include.cmake +++ b/CMake/_Include.cmake @@ -76,6 +76,9 @@ endif() # system checks +include(TestBigEndian) +test_big_endian(WORDS_BIGENDIAN) + check_header(alloca.h) check_header(arpa/inet.h) check_header(dlfcn.h) diff --git a/example/byteorder.cc b/example/byteorder.cc index fdfa0217..58ac5de7 100644 --- a/example/byteorder.cc +++ b/example/byteorder.cc @@ -1,5 +1,5 @@ /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * + * * Libmemcached library * * Copyright (C) 2011 Data Differential, http://datadifferential.com/ @@ -45,7 +45,7 @@ #ifndef swap64 static inline uint64_t swap64(uint64_t in) { -#ifndef WORDS_BIGENDIAN +#if !WORDS_BIGENDIAN /* Little endian, flip the bytes around until someone makes a faster/better * way to do this. */ uint64_t rv= 0; diff --git a/src/libhashkit/jenkins.cc b/src/libhashkit/jenkins.cc index d66c6413..65aa1d11 100644 --- a/src/libhashkit/jenkins.cc +++ b/src/libhashkit/jenkins.cc @@ -1,5 +1,5 @@ /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * + * * HashKit library * * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ @@ -99,7 +99,7 @@ __attribute__((no_sanitize_address,no_sanitize("address"))) uint32_t hashkit_jenkins(const char *key, size_t length, void *) { uint32_t a,b,c; /* internal state */ -#ifndef WORDS_BIGENDIAN +#if !WORDS_BIGENDIAN union { const void *ptr; size_t i; } u; u.ptr = key; #endif @@ -107,7 +107,7 @@ uint32_t hashkit_jenkins(const char *key, size_t length, void *) /* Set up the internal state */ a = b = c = 0xdeadbeef + ((uint32_t)length) + JENKINS_INITVAL; -#ifndef WORDS_BIGENDIAN +#if !WORDS_BIGENDIAN if ((u.i & 0x3) == 0) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ @@ -262,7 +262,7 @@ uint32_t hashkit_jenkins(const char *key, size_t length, void *) case 0 : return c; default : return c; } -#ifndef WORDS_BIGENDIAN +#if !WORDS_BIGENDIAN } #endif diff --git a/src/libmemcached/byteorder.cc b/src/libmemcached/byteorder.cc index 44500add..a32232a9 100644 --- a/src/libmemcached/byteorder.cc +++ b/src/libmemcached/byteorder.cc @@ -1,5 +1,5 @@ /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * + * * Libmemcached library * * Copyright (C) 2011 Data Differential, http://datadifferential.com/ @@ -42,7 +42,7 @@ #ifndef swap64 static inline uint64_t swap64(uint64_t in) { -#ifndef WORDS_BIGENDIAN +#if !WORDS_BIGENDIAN /* Little endian, flip the bytes around until someone makes a faster/better * way to do this. */ uint64_t rv= 0; diff --git a/src/mem_config.h.in b/src/mem_config.h.in index 9609ab40..f761ade0 100644 --- a/src/mem_config.h.in +++ b/src/mem_config.h.in @@ -5,6 +5,8 @@ #define LIBMEMCACHED_WITH_SASL_PWDB "@LIBMEMCACHED_WITH_SASL_PWDB@" #define LIBMEMCACHED_WITH_SASL_CONF "@LIBMEMCACHED_WITH_SASL_CONF@" +#cmakedefine WORDS_BIGENDIAN 1 + #cmakedefine HAVE_C_STDATOMIC 1 #cmakedefine HAVE_CXX_STDATOMIC 1 @@ -56,7 +58,6 @@ #cmakedefine HAVE_WINSOCK2_H 1 #cmakedefine HAVE_WS2TCPIP_H 1 - #cmakedefine HAVE_CINTTYPES 1 #cmakedefine HAVE_CSTDINT 1 #if defined(__cplusplus) -- 2.30.2