author | peter1138 |
Sun, 10 Dec 2006 12:12:26 +0000 | |
changeset 5313 | ea491c0b40f1 |
parent 2719 | 146eaa0ec83c |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
3 |
#include <stdio.h> |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
4 |
|
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
5 |
// This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
6 |
// it does that by putting a 1 and a 0 in an array, and read it out as one |
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
157
diff
changeset
|
7 |
// number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN |
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
8 |
// |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
9 |
// After that it outputs the contents of an include files (endian.h) |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
10 |
// that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
11 |
// care of the real writing to the file. |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
12 |
|
1692
2587eee1c632
(svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents:
200
diff
changeset
|
13 |
int main (int argc, char *argv[]) { |
2713
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
14 |
unsigned char EndianTest[2] = { 1, 0 }; |
2719
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
15 |
int force_BE = 0, force_LE = 0, force_PREPROCESSOR = 0; |
1692
2587eee1c632
(svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents:
200
diff
changeset
|
16 |
|
2713
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
17 |
if (argc > 1 && strcmp(argv[1], "BE") == 0) |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
18 |
force_BE = 1; |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
19 |
if (argc > 1 && strcmp(argv[1], "LE") == 0) |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
20 |
force_LE = 1; |
2719
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
21 |
if (argc > 1 && strcmp(argv[1], "PREPROCESSOR") == 0) |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
22 |
force_PREPROCESSOR = 1; |
1692
2587eee1c632
(svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents:
200
diff
changeset
|
23 |
|
2713
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
24 |
printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n"); |
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
25 |
|
2713
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
26 |
if (force_LE == 1) { |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
27 |
printf("#define TTD_LITTLE_ENDIAN\n"); |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
28 |
} else { |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
29 |
if (force_BE == 1) { |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
30 |
printf("#define TTD_BIG_ENDIAN\n"); |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
31 |
} else { |
2719
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
32 |
if (force_PREPROCESSOR == 1) { |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
33 |
// adding support for universal binaries on OSX |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
34 |
// Universal binaries supports both PPC and x86 |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
35 |
// If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
36 |
printf("#ifdef __BIG_ENDIAN__\n"); |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
37 |
printf("#define TTD_BIG_ENDIAN\n"); |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
38 |
printf("#else\n"); |
2713
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
39 |
printf("#define TTD_LITTLE_ENDIAN\n"); |
2719
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
40 |
printf("#endif\n"); |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
41 |
} else { |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
42 |
if ( *(short *) EndianTest == 1 ) |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
43 |
printf("#define TTD_LITTLE_ENDIAN\n"); |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
44 |
else |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
45 |
printf("#define TTD_BIG_ENDIAN\n"); |
146eaa0ec83c
(svn r3264) -Codechange: [OSX] OSX targets will now always use the preprocessor to determine endianess
bjarni
parents:
2713
diff
changeset
|
46 |
} |
2713
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
47 |
} |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
48 |
} |
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
49 |
printf("#endif\n"); |
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
50 |
|
2713
9f06e1f94ce9
(svn r3258) -Feature: [OSX] added support for universal binaries
bjarni
parents:
2186
diff
changeset
|
51 |
return 0; |
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff
changeset
|
52 |
} |