# HG changeset patch # User Matti Hamalainen # Date 1455512493 -7200 # Node ID f004877a3f51b53ab22b45874d6d15f56cd3f53f # Parent 1b18551b25e747e3516fc35d5d2a0623007da42b Whoops, add the missing endianchk.c diff -r 1b18551b25e7 -r f004877a3f51 endianchk.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/endianchk.c Mon Feb 15 07:01:33 2016 +0200 @@ -0,0 +1,39 @@ +#include + +int main(int argc, char *argv[]) +{ + int val = 0x01020304, ret; + unsigned char *s = (unsigned char *) &val; + char *name = argv[0]; + (void) argc; + + 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" + "\n" + "#define TH_BYTEORDER TH_%s_ENDIAN\n" + "\n" + "#endif /* MY_CONFIG_H */\n" + , + ret ? "LITTLE" : "BIG" + ); + return 0; +} +