]> granicus.if.org Git - postgis/commitdiff
Use own implementation of endian detection, should fix #1172
authorSandro Santilli <strk@keybit.net>
Wed, 21 Dec 2011 14:37:11 +0000 (14:37 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 21 Dec 2011 14:37:11 +0000 (14:37 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8488 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom_internal.h
liblwgeom/lwin_wkb.c
liblwgeom/lwout_wkb.c
liblwgeom/lwutil.c

index 7c6068ca5a60fce86236175d27dceed96a55684c..9cc23d43570350d448581f447524cb20544af34a 100644 (file)
 */
 
 /* Machine endianness */
-#define XDR 0
-#define NDR 1
+#define XDR 0 /* big endian */
+#define NDR 1 /* little endian */
 extern char getMachineEndian(void);
 
 /* Raise an lwerror if srids do not match */
index 9f80d512e8bd9df7a613d613bfc0c39256140b13..34f2a5392a99ce66435ceaf9f11d8993d39308d4 100644 (file)
@@ -11,7 +11,6 @@
 
 #include "liblwgeom_internal.h"
 #include "lwgeom_log.h"
-#include <sys/param.h>
 
 /**
 * Used for passing the parse state between the parsing functions.
@@ -625,7 +624,7 @@ LWGEOM* lwgeom_from_wkb_state(wkb_parse_state *s)
 
        /* Check the endianness of our input  */
        s->swap_bytes = LW_FALSE;
-       if( BYTE_ORDER == LITTLE_ENDIAN ) /* Machine arch is little */
+       if( getMachineEndian() == NDR ) /* Machine arch is little */
        {
                if ( ! wkb_little_endian )    /* Data is big! */
                        s->swap_bytes = LW_TRUE;
index bb2572cd791599e576953045483249c941ef6109..723ac75ae5b726d292296a4222cf709351ace221 100644 (file)
@@ -11,7 +11,6 @@
 
 #include "liblwgeom_internal.h"
 #include "lwgeom_log.h"
-#include <sys/param.h>
 
 static uint8_t* lwgeom_to_wkb_buf(const LWGEOM *geom, uint8_t *buf, uint8_t variant);
 static size_t lwgeom_to_wkb_size(const LWGEOM *geom, uint8_t variant);
@@ -167,8 +166,8 @@ static uint8_t* endian_to_wkb_buf(uint8_t *buf, uint8_t variant)
 static inline int wkb_swap_bytes(uint8_t variant)
 {
        /* If requested variant matches machine arch, we don't have to swap! */
-       if ( ((variant & WKB_NDR) && (BYTE_ORDER == LITTLE_ENDIAN)) ||
-            ((! (variant & WKB_NDR)) && (BYTE_ORDER == BIG_ENDIAN)) )
+       if ( ((variant & WKB_NDR) && (getMachineEndian() == NDR)) ||
+            ((! (variant & WKB_NDR)) && (getMachineEndian() == XDR)) )
        {
                return LW_FALSE;
        }
@@ -716,7 +715,7 @@ uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
        if ( ! (variant & WKB_NDR || variant & WKB_XDR) ||
               (variant & WKB_NDR && variant & WKB_XDR) )
        {
-               if ( BYTE_ORDER == LITTLE_ENDIAN ) 
+               if ( getMachineEndian() == NDR ) 
                        variant = variant | WKB_NDR;
                else
                        variant = variant | WKB_XDR;
index 7581108e91f3dc67ceff50190e5f94f5c8b7242f..a9bcd8a5f604f4ce7b595334168398e30fcd270d 100644 (file)
@@ -355,8 +355,8 @@ getMachineEndian(void)
        static int endian_check_int = 1; /* dont modify this!!! */
 
        return *((char *) &endian_check_int); /* 0 = big endian | xdr,
-                                                      * 1 = little endian | ndr
-                                                      */
+                                              * 1 = little endian | ndr
+                                              */
 }