#ifdef WORDS_BIGENDIAN
#define SIZE_GET(varsize) ((varsize) & 0x3FFFFFFF)
#define SIZE_SET(varsize, len) ((varsize) = ((len) & 0x3FFFFFFF))
+#define IS_BIG_ENDIAN 1
#else
#define SIZE_GET(varsize) (((varsize) >> 2) & 0x3FFFFFFF)
#define SIZE_SET(varsize, len) ((varsize) = (((uint32_t)(len)) << 2))
+#define IS_BIG_ENDIAN 0
#endif
/**
/* Machine endianness */
#define XDR 0 /* big endian */
#define NDR 1 /* little endian */
-extern char getMachineEndian(void);
uint64_t uint32_interleave_2(uint32_t u1, uint32_t u2);
* My best guess at if you are big-endian or little-endian. This may
* need adjustment.
*/
-#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
+#if (defined(WORDS_BIGENDIAN))
+# define HASH_LITTLE_ENDIAN 0
+# define HASH_BIG_ENDIAN 1
+#elif (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
__BYTE_ORDER == __LITTLE_ENDIAN) || \
(defined(i386) || defined(__i386__) || defined(__i486__) || \
defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL))
#define hashmask(n) (hashsize(n)-1)
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
-
#if 0
static uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval);
static void hashword2 (const uint32_t *k, size_t length, uint32_t *pc, uint32_t *pb);
/* Check the endianness of our input */
s->swap_bytes = LW_FALSE;
- if( getMachineEndian() == NDR ) /* Machine arch is little */
- {
- if ( ! wkb_little_endian ) /* Data is big! */
- s->swap_bytes = LW_TRUE;
- }
- else /* Machine arch is big */
- {
- if ( wkb_little_endian ) /* Data is little! */
- s->swap_bytes = LW_TRUE;
- }
+
+ /* Machine arch is big endian, request is for little */
+ if (IS_BIG_ENDIAN && wkb_little_endian)
+ s->swap_bytes = LW_TRUE;
+ /* Machine arch is little endian, request is for big */
+ else if ((!IS_BIG_ENDIAN) && (!wkb_little_endian))
+ s->swap_bytes = LW_TRUE;
/* Read the type number */
wkb_type = integer_from_wkb_state(s);
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) && (getMachineEndian() == NDR)) ||
- ((! (variant & WKB_NDR)) && (getMachineEndian() == XDR)) )
+ if (((variant & WKB_NDR) && !IS_BIG_ENDIAN) ||
+ ((!(variant & WKB_NDR)) && IS_BIG_ENDIAN))
{
return LW_FALSE;
}
if ( ! (variant & WKB_NDR || variant & WKB_XDR) ||
(variant & WKB_NDR && variant & WKB_XDR) )
{
- if ( getMachineEndian() == NDR )
- variant = variant | WKB_NDR;
- else
+ if (IS_BIG_ENDIAN)
variant = variant | WKB_XDR;
+ else
+ variant = variant | WKB_NDR;
}
/* Allocate the buffer */
}
-char
-getMachineEndian(void)
-{
- static int endian_check_int = 1; /* don't modify this!!! */
-
- return *((char *) &endian_check_int); /* 0 = big endian | xdr,
- * 1 = little endian | ndr
- */
-}
-
void
error_if_srid_mismatch(int32_t srid1, int32_t srid2)
{