Mercurial > hg > th-libs
annotate endianchk.c @ 780:847d1ebe5b81
Indent cosmetic.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 04 Jul 2023 01:22:50 +0300 |
parents | 2991e6b52d95 |
children |
rev | line source |
---|---|
258
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 #include <stdio.h> |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 int main(int argc, char *argv[]) |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 { |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 int val = 0x01020304, ret; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 unsigned char *s = (unsigned char *) &val; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 char *name = argv[0]; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 (void) argc; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 if (sizeof(int) != 4) |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 { |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 fprintf(stderr, "%s: sizeof(int) is not 32 bits!\n", name); |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 return -1; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 } |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 if (s[0] == 0x01 && s[1] == 0x02 && s[2] == 0x03 && s[3] == 0x04) |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 ret = 0; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 else |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 if (s[0] == 0x04 && s[1] == 0x03 && s[2] == 0x02 && s[3] == 0x01) |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 ret = 1; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 else |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 { |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 fprintf(stderr, "%s: Unsupported endianess.\n", name); |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 return -2; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 } |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 printf( |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 "#ifndef MY_CONFIG_H\n" |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 "#define MY_CONFIG_H 1\n" |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 "\n" |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 "#define TH_BYTEORDER TH_%s_ENDIAN\n" |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 "\n" |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 "#endif /* MY_CONFIG_H */\n" |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 , |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 ret ? "LITTLE" : "BIG" |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 ); |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 return 0; |
d746fd5975f4
Add endian checking utility for building the tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 } |
441
2991e6b52d95
Get rid of trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
39 |