Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1240)

Unified Diff: src/ots.cc

Issue 10273021: Revive Tag() function (Closed) Base URL: http://ots.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ots.cc
===================================================================
--- src/ots.cc (revision 88)
+++ src/ots.cc (working copy)
@@ -83,10 +83,36 @@
// Use a macro instead of a function because gcc 4.4.3 creates static
// initializers in that case.
-#if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
-#define TAG(d, c, b, a) (a | (b << 8) | (c << 16) | (d << 24))
-#else
-#define TAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24))
+// Try endianness checks with zero, one and two leading underscores,
Yusuke Sato 2012/05/01 02:23:31 The #ifdefs look too complex to me. What about rev
bashi 2012/05/01 04:05:49 Done. Thank you for suggestion!
+// as the symbols actually defined seem to vary between systems. (Sigh.)
+#if defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) && defined(BYTE_ORDER)
+# if BYTE_ORDER == BIG_ENDIAN
+# define TAG(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
+# elif BYTE_ORDER == LITTLE_ENDIAN
+# define TAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24))
+# else
+# error "unsupported byte order!"
+# endif
+#elif defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) && defined(_BYTE_ORDER)
+# if _BYTE_ORDER == _BIG_ENDIAN
+# define TAG(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
+# elif _BYTE_ORDER == _LITTLE_ENDIAN
+# define TAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24))
+# else
+# error "unsupported byte order!"
+# endif
+#elif defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) && defined(__BYTE_ORDER)
+# if __BYTE_ORDER == __BIG_ENDIAN
+# define TAG(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
+# elif __BYTE_ORDER == __LITTLE_ENDIAN
+# define TAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24))
+# else
+# error "unsupported byte order!"
+# endif
+#elif defined(__BIG_ENDIAN__)
+# define TAG(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
+#else // fall back to assuming little-endian
+# define TAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24))
#endif
const struct {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698