changeset 117:36552c7d7171

Merged.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 15 Feb 2016 15:24:17 +0200
parents 9a0aeb9ce9ba (diff) d062312ea850 (current diff)
children 24583e5ca0b3
files
diffstat 1 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/endianchk.c	Mon Feb 15 12:00:32 2016 +0200
+++ b/endianchk.c	Mon Feb 15 15:24:17 2016 +0200
@@ -2,11 +2,28 @@
 
 int main(int argc, char *argv[])
 {
-    int val = 1, ret;
-    char *s = (char *) &val;
+    int val = 0x01020304, ret;
+    unsigned char *s = (unsigned char *) &val;
+    char *name = argv[0];
     (void) argc;
-    (void) argv;
-    ret = (int)(*s);
+
+    if (sizeof(int) != 4)
+    {
+        fprintf(stderr, "%s: sizeof(int) is not 32 bits!\n", name);
+        return -1;
+    }
+
+    if (s[0] == 0x01 && s[1] == 0x02 && s[2] == 0x03 && s[3] == 0x04)
+        ret = 0;
+    else
+    if (s[0] == 0x04 && s[1] == 0x03 && s[2] == 0x02 && s[3] == 0x01)
+        ret = 1;
+    else
+    {
+        fprintf(stderr, "%s: Unsupported endianess.\n", name);
+        return -2;
+    }
+
     printf(
         "#ifndef MY_CONFIG_H\n"
         "#define MY_CONFIG_H 1\n"