]> git.zerfleddert.de Git - micropolis/blobdiff - src/sim/s_fileio.c
automatic byteorder detection
[micropolis] / src / sim / s_fileio.c
index 3768f01d847ec27be7020380ad8de0d3c47f4aca..37637f7ac484b4979b4362ba6126710099c11a0f 100644 (file)
 #include "sim.h"
 
 
-#if defined(MSDOS) || defined(OSF1) || defined(IS_INTEL)
-
 #define SWAP_SHORTS(a,b)       _swap_shorts(a,b)
 #define SWAP_LONGS(a,b)                _swap_longs(a,b)
 #define HALF_SWAP_LONGS(a,b)   _half_swap_longs(a,b)
 
+#define NOOP_ON_BE     { int test = 1; if (!(*(unsigned char*) (&test))) return; }
+
 static void
 _swap_shorts(short *buf, int len)
 {
   int i;
 
+  NOOP_ON_BE;
+
   /* Flip bytes in each short! */
   for (i = 0; i < len; i++) {  
     *buf = ((*buf & 0xFF) <<8) | ((*buf &0xFF00) >>8);
@@ -85,6 +87,8 @@ _swap_longs(long *buf, int len)
 {
   int i;
 
+  NOOP_ON_BE;
+
   /* Flip bytes in each long! */
   for (i = 0; i < len; i++) {  
     long l = *buf;
@@ -102,6 +106,8 @@ _half_swap_longs(long *buf, int len)
 {
   int i;
 
+  NOOP_ON_BE
+
   /* Flip bytes in each long! */
   for (i = 0; i < len; i++) {  
     long l = *buf;
@@ -112,15 +118,6 @@ _half_swap_longs(long *buf, int len)
   }
 }
 
-#else
-
-#define SWAP_SHORTS(a, b)
-#define SWAP_LONGS(a, b)
-#define HALF_SWAP_LONGS(a, b)
-
-#endif
-
-
 static int
 _load_short(short *buf, int len, FILE *f)
 {
Impressum, Datenschutz