Mercurial > hg > nnchat
annotate endianchk.c @ 669:32c13602c091
Some functions used were factored into new th_datastruct module in th-libs,
so include the necessary header file as needed, and build the module object.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 17 Feb 2016 14:28:17 +0200 |
parents | f004877a3f51 |
children |
rev | line source |
---|---|
667
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 #include <stdio.h> |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 int main(int argc, char *argv[]) |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 { |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 int val = 0x01020304, ret; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 unsigned char *s = (unsigned char *) &val; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 char *name = argv[0]; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 (void) argc; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 if (sizeof(int) != 4) |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 { |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 fprintf(stderr, "%s: sizeof(int) is not 32 bits!\n", name); |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 return -1; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 } |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 if (s[0] == 0x01 && s[1] == 0x02 && s[2] == 0x03 && s[3] == 0x04) |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 ret = 0; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 else |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 if (s[0] == 0x04 && s[1] == 0x03 && s[2] == 0x02 && s[3] == 0x01) |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 ret = 1; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 else |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 { |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 fprintf(stderr, "%s: Unsupported endianess.\n", name); |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 return -2; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 } |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 printf( |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 "#ifndef MY_CONFIG_H\n" |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 "#define MY_CONFIG_H 1\n" |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 "\n" |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 "#define TH_BYTEORDER TH_%s_ENDIAN\n" |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 "\n" |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 "#endif /* MY_CONFIG_H */\n" |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 , |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 ret ? "LITTLE" : "BIG" |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 ); |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 return 0; |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 } |
f004877a3f51
Whoops, add the missing endianchk.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 |