endian_check.c
author tron
Sun, 14 Aug 2005 18:10:18 +0000
changeset 2340 e18ef06bc59a
parent 2186 db48cf29b983
child 2713 9c42385e4f41
permissions -rw-r--r--
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
This doesn't ease the global variable mess, but makes the distinction between sprite heap and gfx loading routines easier.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1692
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1692
diff changeset
     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
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    13
int main (int argc, char *argv[]) {
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    14
  unsigned char EndianTest[2] = { 1, 0 };
1692
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    15
  int force_BE = 0, force_LE = 0;
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    16
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    17
  if (argc > 1 && strcmp(argv[1], "BE") == 0)
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    18
    force_BE = 1;
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    19
  if (argc > 1 && strcmp(argv[1], "LE") == 0)
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    20
    force_LE = 1;
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    21
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    22
  printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
1692
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    23
0b52df38cabc (svn r2196) -Change: updated the Makefile, now it works for crossplatform compiling
TrueLight
parents: 200
diff changeset
    24
  if ( (*(short *) EndianTest == 1 && force_BE != 1) || force_LE == 1)
157
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    25
    printf("#define TTD_LITTLE_ENDIAN\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    26
  else
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    27
    printf("#define TTD_BIG_ENDIAN\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    28
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    29
  printf("#endif\n");
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    30
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    31
  return 0;
dd017fa3bad8 (svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
diff changeset
    32
}