aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-02-16 16:11:36 +0100
committerMattias Andrée <maandree@kth.se>2022-02-16 16:11:36 +0100
commitd6f303ab33bdb97fa50a7daba6d4fa489a9feca2 (patch)
treeb36af440b4d97d7b13dc49683168c4fc18dbe463 /common.h
parentFix style + minimal optimisation (diff)
downloadlibar2-d6f303ab33bdb97fa50a7daba6d4fa489a9feca2.tar.gz
libar2-d6f303ab33bdb97fa50a7daba6d4fa489a9feca2.tar.bz2
libar2-d6f303ab33bdb97fa50a7daba6d4fa489a9feca2.tar.xz
Small optimisation for little-endian machines
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'common.h')
-rw-r--r--common.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/common.h b/common.h
index e02d2c6..8863661 100644
--- a/common.h
+++ b/common.h
@@ -54,6 +54,28 @@
#endif
+#define LITTLE_ENDIAN__ 1234
+#define BIG_ENDIAN__ 4321
+#ifndef HOST_ENDIAN
+# if defined(i386) || defined(__i386__) || defined(__x86_64__)
+# define HOST_ENDIAN LITTLE_ENDIAN__
+# endif
+#endif
+#ifdef HOST_ENDIAN
+# if HOST_ENDIAN == LITTLE_ENDIAN__
+# define USING_LITTLE_ENDIAN
+# elif HOST_ENDIAN == BIG_ENDIAN__
+# define USING_BIG_ENDIAN
+# endif
+#else
+# ifdef __GNUC__
+# ifdef WARN_UNKNOWN_ENDIAN
+# warning The host endian is unknown
+# endif
+# endif
+#endif
+
+
#define ELEMSOF(ARR) (sizeof(ARR) / sizeof(*(ARR)))
#define MAX(A, B) ((A) > (B) ? (A) : (B))