From 77de1c473a74b5ba473b099dd608324357f65cb4 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 23 Nov 2020 14:37:01 +0100 Subject: [PATCH] Determine endianness at compile time --- libvips/iofuncs/util.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index c78b0e0d..b986e275 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1602,16 +1602,13 @@ vips_ispoweroftwo( int p ) int vips_amiMSBfirst( void ) { - int test; - unsigned char *p = (unsigned char *) &test; - - test = 0; - p[0] = 255; - - if( test == 255 ) - return( 0 ); - else - return( 1 ); +#if G_BYTE_ORDER == G_BIG_ENDIAN + return( 1 ); +#elif G_BYTE_ORDER == G_LITTLE_ENDIAN + return( 0 ); +#else +#error "Byte order not recognised" +#endif } /* Return the tmp dir. On Windows, GetTempPath() will also check the values of