X-Git-Url: https://git.openstreetmap.org/nominatim.git/blobdiff_plain/ab6a99677293c9ddb96a717f03b8a009e98ab955..dd5315cbaa75035d27265abb781299670c2a02cd:/nominatim/postgresql.h diff --git a/nominatim/postgresql.h b/nominatim/postgresql.h index ebece610..f30e7308 100644 --- a/nominatim/postgresql.h +++ b/nominatim/postgresql.h @@ -7,14 +7,32 @@ #define PG_OID_INT8 20 #define PG_OID_INT4 23 -#if __BYTE_ORDER == __BIG_ENDIAN -#define PGint16(x) (x) +#if HAVE_BYTESWAP +#include +#define PG_BSWAP32(x) bswap_32(x) +#define PG_BSWAP64(x) bswap_64(x) +#elif HAVE_SYS_ENDIAN +#include +#define PG_BSWAP32(x) bswap32(x) +#define PG_BSWAP64(x) bswap64(x) +#else +#error "No appropriate byteswap found for your system." +#endif + +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#define PGint32(x) (x) +#define PGint64(x) (x) +#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define PGint32(x) PG_BSWAP32(x) +#define PGint64(x) PG_BSWAP64(x) +#elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN) #define PGint32(x) (x) #define PGint64(x) (x) +#elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN) +#define PGint32(x) PG_BSWAP32(x) +#define PGint64(x) PG_BSWAP64(x) #else -#define PGint16(x) __bswap_16 (x) -#define PGint32(x) __bswap_32 (x) -#define PGint64(x) __bswap_64 (x) +#error "Cannot determine byte order." #endif const char *build_conninfo(const char *db, const char *username, const char *password, const char *host, const char *port);