summaryrefslogtreecommitdiff
path: root/src/sysdeps/tryendianness.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-09-18 18:55:44 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-09-18 18:55:44 +0000
commit3534b428629be185e096be99e3bd5fdfe32d5544 (patch)
tree210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/sysdeps/tryendianness.c
downloadskalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/sysdeps/tryendianness.c')
-rw-r--r--src/sysdeps/tryendianness.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/sysdeps/tryendianness.c b/src/sysdeps/tryendianness.c
new file mode 100644
index 0000000..3fa1938
--- /dev/null
+++ b/src/sysdeps/tryendianness.c
@@ -0,0 +1,43 @@
+/* ISC license. */
+
+#include <stdio.h>
+
+int main (void)
+{
+ unsigned long i = 0xdeadbeefUL ;
+ if (sizeof(unsigned long) == 4)
+ if ((((unsigned char *)(&i))[0] == 0xef)
+ && (((unsigned char *)(&i))[1] == 0xbe)
+ && (((unsigned char *)(&i))[2] == 0xad)
+ && (((unsigned char *)(&i))[3] == 0xde))
+ return (puts("little"), 0) ;
+ else if ((((unsigned char *)(&i))[0] == 0xde)
+ && (((unsigned char *)(&i))[1] == 0xad)
+ && (((unsigned char *)(&i))[2] == 0xbe)
+ && (((unsigned char *)(&i))[3] == 0xef))
+ return (puts("big"), 0) ;
+ else return (puts("unknown"), 1) ;
+ else if (sizeof(unsigned long) == 8)
+ if ((((unsigned char *)(&i))[0] == 0xef)
+ && (((unsigned char *)(&i))[1] == 0xbe)
+ && (((unsigned char *)(&i))[2] == 0xad)
+ && (((unsigned char *)(&i))[3] == 0xde)
+ && (((unsigned char *)(&i))[4] == 0x00)
+ && (((unsigned char *)(&i))[5] == 0x00)
+ && (((unsigned char *)(&i))[6] == 0x00)
+ && (((unsigned char *)(&i))[7] == 0x00))
+ return (puts("little"), 0) ;
+ else if (sizeof(unsigned long) == 8)
+ if ((((unsigned char *)(&i))[0] == 0x00)
+ && (((unsigned char *)(&i))[1] == 0x00)
+ && (((unsigned char *)(&i))[2] == 0x00)
+ && (((unsigned char *)(&i))[3] == 0x00)
+ && (((unsigned char *)(&i))[4] == 0xde)
+ && (((unsigned char *)(&i))[5] == 0xad)
+ && (((unsigned char *)(&i))[6] == 0xbe)
+ && (((unsigned char *)(&i))[7] == 0xef))
+ return (puts("big"), 0) ;
+ else return (puts("unknown"), 1) ;
+ else return 1 ;
+ else return (puts("unknown unsigned long size"), 1) ;
+}