Byte order determination

Philipp Thomas <[email protected]> Fri, 27 Nov 2015 13:53:27 +0100
Newsgroups gmane.comp.security.passwordsafe.devel
Organization SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton, HRB 21284 (AG Nürnberg)
Message-ID <[email protected]>
When looking into build failures on architectures other than intel I
discovered that passwordsafe defines endianess based on the architecture.

I propose to simply include endian.h and check what glibc/gcc have set
__BYTE_ORDER to. With this change passwordsafe builds and works on all
platforms openSUSE supports, i.e. aarm64, ppc64le, s390x and ppc/ppc64.

Philipp

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140

_______________________________________________
Passwordsafe-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/passwordsafe-devel
passwordsafe-use___BYTE_ORDER.patch (text/x-patch, 1.9 KB)
From: Philipp Thomas <[email protected]>
Date: 2015-11-25 15:01:27+01:00
Subject: Fix endianess detection.

Just use glibc's/gcc's predefined macro to determine endianess.

Signed-off-by: [email protected]

---
 src/core/PwsPlatform.h |   25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Index: src/core/PwsPlatform.h
===================================================================
--- src/core/PwsPlatform.h.orig	2015-06-12 10:25:38.000000000 +0200
+++ src/core/PwsPlatform.h	2015-11-27 13:40:33.594290020 +0100
@@ -60,9 +60,14 @@
 
 // Following seems needed on Linux/cygwin
 #if defined(__linux__) || defined(__CYGWIN__)
+#include <endian.h>
 #define LTC_NO_ROLC
 #endif
 
+#if defined(__linux__) || defined(__CYGWIN__)
+#include <endian.h>
+#endif
+
 #undef PWS_PLATFORM
 #undef POCKET_PC
 
@@ -90,17 +95,19 @@
 // * Windows 32                                 *
 // **********************************************
 #if defined(_WIN32)
-#if defined(x86) || defined(_x86) || defined(_X86) || defined(_X86_) || defined(_M_IX86) || defined(_M_X64)
-#define PWS_PLATFORM "Windows"
-#define PWS_LITTLE_ENDIAN
-#endif
+  #if defined(x86) || defined(_x86) || defined(_X86) || defined(_X86_) || defined(_M_IX86) || defined(_M_X64)
+    #define PWS_PLATFORM "Windows"
+    #define PWS_LITTLE_ENDIAN
+  #endif
 // **********************************************
-// * Linux on Intel                             *
+// * Linux                                      *
 // **********************************************
-#elif defined(__linux)
-#define PWS_PLATFORM "Linux"
-#if defined(__i386__) || defined(__i486__) || defined(__x86_64__)
-#define PWS_LITTLE_ENDIAN
+#elif defined(__linux) || defined(__linux__)
+  #define PWS_PLATFORM "Linux"
+  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+    #define PWS_LITTLE_ENDIAN
+  #else
+    #define PWS_BIG_ENDIAN
 #endif
 // **********************************************
 // * cygwin on Intel                             *