comparison endianchk.c @ 667:f004877a3f51

Whoops, add the missing endianchk.c
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 15 Feb 2016 07:01:33 +0200
parents
children
comparison
equal deleted inserted replaced
666:1b18551b25e7 667:f004877a3f51
1 #include <stdio.h>
2
3 int main(int argc, char *argv[])
4 {
5 int val = 0x01020304, ret;
6 unsigned char *s = (unsigned char *) &val;
7 char *name = argv[0];
8 (void) argc;
9
10 if (sizeof(int) != 4)
11 {
12 fprintf(stderr, "%s: sizeof(int) is not 32 bits!\n", name);
13 return -1;
14 }
15
16 if (s[0] == 0x01 && s[1] == 0x02 && s[2] == 0x03 && s[3] == 0x04)
17 ret = 0;
18 else
19 if (s[0] == 0x04 && s[1] == 0x03 && s[2] == 0x02 && s[3] == 0x01)
20 ret = 1;
21 else
22 {
23 fprintf(stderr, "%s: Unsupported endianess.\n", name);
24 return -2;
25 }
26
27 printf(
28 "#ifndef MY_CONFIG_H\n"
29 "#define MY_CONFIG_H 1\n"
30 "\n"
31 "#define TH_BYTEORDER TH_%s_ENDIAN\n"
32 "\n"
33 "#endif /* MY_CONFIG_H */\n"
34 ,
35 ret ? "LITTLE" : "BIG"
36 );
37 return 0;
38 }
39