equal
deleted
inserted
replaced
6 // |
6 // |
7 // After that it outputs the contents of an include files (endian.h) |
7 // After that it outputs the contents of an include files (endian.h) |
8 // that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes |
8 // that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes |
9 // care of the real writing to the file. |
9 // care of the real writing to the file. |
10 |
10 |
11 int main () { |
11 int main (int argc, char *argv[]) { |
12 unsigned char EndianTest[2] = { 1, 0 }; |
12 unsigned char EndianTest[2] = { 1, 0 }; |
|
13 int force_BE = 0, force_LE = 0; |
|
14 |
|
15 if (argc > 1 && strcmp(argv[1], "BE") == 0) |
|
16 force_BE = 1; |
|
17 if (argc > 1 && strcmp(argv[1], "LE") == 0) |
|
18 force_LE = 1; |
|
19 |
13 printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n"); |
20 printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n"); |
14 if( *(short *) EndianTest == 1 ) |
21 |
|
22 if ( (*(short *) EndianTest == 1 && force_BE != 1) || force_LE == 1) |
15 printf("#define TTD_LITTLE_ENDIAN\n"); |
23 printf("#define TTD_LITTLE_ENDIAN\n"); |
16 else |
24 else |
17 printf("#define TTD_BIG_ENDIAN\n"); |
25 printf("#define TTD_BIG_ENDIAN\n"); |
18 |
26 |
19 printf("#endif\n"); |
27 printf("#endif\n"); |