shithub: sox

Download patch

ref: 2cfab89817a38efdfb6422e3217e53695d4b0f5c
parent: 6d2efb5fa5417b1bf2c7c37e1c6220ec74f591fa
author: cbagwell <cbagwell>
date: Mon Aug 14 22:10:57 EDT 2000

Added macros to test for big endian and little endian machines.
Made use of this in the sphere format.

--- a/configure
+++ b/configure
@@ -1144,16 +1144,108 @@
 fi
 
 
+echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6
+echo "configure:1149: checking whether byte ordering is bigendian" >&5
+if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_cv_c_bigendian=unknown
+# See if sys/param.h defines the BYTE_ORDER macro.
+cat > conftest.$ac_ext <<EOF
+#line 1156 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+#include <sys/param.h>
+int main() {
 
+#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
+ bogus endian macros
+#endif
+; return 0; }
+EOF
+if { (eval echo configure:1167: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  rm -rf conftest*
+  # It does; now see whether it defined to BIG_ENDIAN or not.
+cat > conftest.$ac_ext <<EOF
+#line 1171 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+#include <sys/param.h>
+int main() {
+
+#if BYTE_ORDER != BIG_ENDIAN
+ not big endian
+#endif
+; return 0; }
+EOF
+if { (eval echo configure:1182: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  rm -rf conftest*
+  ac_cv_c_bigendian=yes
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  ac_cv_c_bigendian=no
+fi
+rm -f conftest*
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+fi
+rm -f conftest*
+if test $ac_cv_c_bigendian = unknown; then
+if test "$cross_compiling" = yes; then
+    { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1202 "configure"
+#include "confdefs.h"
+main () {
+  /* Are we little or big endian?  From Harbison&Steele.  */
+  union
+  {
+    long l;
+    char c[sizeof (long)];
+  } u;
+  u.l = 1;
+  exit (u.c[sizeof (long) - 1] == 1);
+}
+EOF
+if { (eval echo configure:1215: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+then
+  ac_cv_c_bigendian=no
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -fr conftest*
+  ac_cv_c_bigendian=yes
+fi
+rm -fr conftest*
+fi
+
+fi
+fi
+
+echo "$ac_t""$ac_cv_c_bigendian" 1>&6
+if test $ac_cv_c_bigendian = yes; then
+  cat >> confdefs.h <<\EOF
+#define WORDS_BIGENDIAN 1
+EOF
+
+fi
+
+
+
+
 echo "checking if math library is required during link" 1>&6
-echo "configure:1150: checking if math library is required during link" >&5
+echo "configure:1242: checking if math library is required during link" >&5
 echo $ac_n "checking for pow""... $ac_c" 1>&6
-echo "configure:1152: checking for pow" >&5
+echo "configure:1244: checking for pow" >&5
 if eval "test \"`echo '$''{'ac_cv_func_pow'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1157 "configure"
+#line 1249 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char pow(); below.  */
@@ -1176,7 +1268,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1180: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1272: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_pow=yes"
 else
@@ -1198,7 +1290,7 @@
 if test "$ac_cv_func_pow" = no
 then
   echo $ac_n "checking for pow in -lm""... $ac_c" 1>&6
-echo "configure:1202: checking for pow in -lm" >&5
+echo "configure:1294: checking for pow in -lm" >&5
 ac_lib_var=`echo m'_'pow | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1206,7 +1298,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lm  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1210 "configure"
+#line 1302 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1217,7 +1309,7 @@
 pow()
 ; return 0; }
 EOF
-if { (eval echo configure:1221: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1313: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1265,17 +1357,17 @@
 
 ac_safe=`echo "gsm.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for gsm.h""... $ac_c" 1>&6
-echo "configure:1269: checking for gsm.h" >&5
+echo "configure:1361: checking for gsm.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1274 "configure"
+#line 1366 "configure"
 #include "confdefs.h"
 #include <gsm.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1279: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1371: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1300,7 +1392,7 @@
 if test "$gsminc" = yes
 then
   echo $ac_n "checking for gsm_create in -lgsm""... $ac_c" 1>&6
-echo "configure:1304: checking for gsm_create in -lgsm" >&5
+echo "configure:1396: checking for gsm_create in -lgsm" >&5
 ac_lib_var=`echo gsm'_'gsm_create | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1308,7 +1400,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lgsm  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1312 "configure"
+#line 1404 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1319,7 +1411,7 @@
 gsm_create()
 ; return 0; }
 EOF
-if { (eval echo configure:1323: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1415: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1354,17 +1446,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1358: checking for $ac_hdr" >&5
+echo "configure:1450: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1363 "configure"
+#line 1455 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1368: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1460: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1395,12 +1487,12 @@
 for ac_func in getopt strerror memmove rand
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1399: checking for $ac_func" >&5
+echo "configure:1491: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1404 "configure"
+#line 1496 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -1423,7 +1515,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1427: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1519: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -1452,7 +1544,7 @@
 if test "$alsa_dsp" = auto
 then
 	echo $ac_n "checking whether /proc/asound is functional (ALSA)""... $ac_c" 1>&6
-echo "configure:1456: checking whether /proc/asound is functional (ALSA)" >&5
+echo "configure:1548: checking whether /proc/asound is functional (ALSA)" >&5
 if eval "test \"`echo '$''{'ac_cv_dev_alsa_dsp'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1460,7 +1552,7 @@
   ac_cv_dev_alsa_dsp=no
 else
   cat > conftest.$ac_ext <<EOF
-#line 1464 "configure"
+#line 1556 "configure"
 #include "confdefs.h"
 
 			void *opendir(const char *);
@@ -1478,7 +1570,7 @@
 				}
 			
 EOF
-if { (eval echo configure:1482: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1574: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_dev_alsa_dsp=yes
 else
@@ -1500,17 +1592,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1504: checking for $ac_hdr" >&5
+echo "configure:1596: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1509 "configure"
+#line 1601 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1514: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1606: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1550,17 +1642,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1554: checking for $ac_hdr" >&5
+echo "configure:1646: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1559 "configure"
+#line 1651 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1564: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1656: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1595,7 +1687,7 @@
 if test "$oss_dsp" = auto
 then
 	echo $ac_n "checking whether /dev/dsp is functional (OSS)""... $ac_c" 1>&6
-echo "configure:1599: checking whether /dev/dsp is functional (OSS)" >&5
+echo "configure:1691: checking whether /dev/dsp is functional (OSS)" >&5
 if eval "test \"`echo '$''{'ac_cv_dev_oss_dsp'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1603,7 +1695,7 @@
   ac_cv_dev_oss_dsp=no
 else
   cat > conftest.$ac_ext <<EOF
-#line 1607 "configure"
+#line 1699 "configure"
 #include "confdefs.h"
 
 			int open(const char *, int);
@@ -1621,7 +1713,7 @@
 				}
 			
 EOF
-if { (eval echo configure:1625: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1717: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_dev_oss_dsp=yes
 else
@@ -1643,17 +1735,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1647: checking for $ac_hdr" >&5
+echo "configure:1739: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1652 "configure"
+#line 1744 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1657: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1749: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1693,17 +1785,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1697: checking for $ac_hdr" >&5
+echo "configure:1789: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1702 "configure"
+#line 1794 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1707: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1799: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1738,7 +1830,7 @@
 if test "$sun_audio" = auto
 then
 	echo $ac_n "checking whether /dev/audio is functional (SUN style)""... $ac_c" 1>&6
-echo "configure:1742: checking whether /dev/audio is functional (SUN style)" >&5
+echo "configure:1834: checking whether /dev/audio is functional (SUN style)" >&5
 if eval "test \"`echo '$''{'ac_cv_dev_sun_audio'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1746,7 +1838,7 @@
   ac_cv_dev_sun_audio=no
 else
   cat > conftest.$ac_ext <<EOF
-#line 1750 "configure"
+#line 1842 "configure"
 #include "confdefs.h"
 
 			int open(const char *, int);
@@ -1764,7 +1856,7 @@
 				}
 			
 EOF
-if { (eval echo configure:1768: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1860: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_dev_sun_audio=yes
 else
@@ -1786,17 +1878,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1790: checking for $ac_hdr" >&5
+echo "configure:1882: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1795 "configure"
+#line 1887 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1800: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1892: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1836,17 +1928,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1840: checking for $ac_hdr" >&5
+echo "configure:1932: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1845 "configure"
+#line 1937 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1850: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1942: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
--- a/configure.in
+++ b/configure.in
@@ -85,6 +85,10 @@
     CFLAGS="$CFLAGS -Wall"
 fi
 
+dnl Check for system dependent features.
+
+AC_C_BIGENDIAN
+
 dnl Checks for libraries.
 
 dnl Check if math library is needed.
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -40,16 +40,13 @@
 	ULONG channels;
 	unsigned short rate;
 	int i;
-	int littlendian = 1;
-	char *endptr;
 
 	ULONG chan1_pos;
 
-	endptr = (char*) &littlendian;
 	/* 8svx is in big endian format. Swap whats
 	 * read in on little endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
@@ -260,14 +257,10 @@
 	struct svxpriv *p = (struct svxpriv *) ft->priv;
 	int i;
 
-	int littlendian = 1;
-	char *endptr;
-
-	endptr = (char *) &littlendian;
 	/* 8svx is in big endian format.  Swaps wahst
 	 * read in on little endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -80,8 +80,6 @@
 	double rate = 0.0;
 	ULONG offset = 0;
 	ULONG blocksize = 0;
-	int littlendian = 1;
-	char *endptr;
 	int foundcomm = 0, foundmark = 0, foundinstr = 0;
 	struct mark {
 		unsigned short id;
@@ -109,8 +107,7 @@
 
 	/* AIFF is in Big Endian format.  Swap whats read in on Little */
 	/* Endian machines.                                            */
-	endptr = (char *) &littlendian;
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 	    ft->swap = ft->swap ? 0 : 1;
 	}
@@ -614,8 +611,6 @@
 ft_t ft;
 {
 	struct aiffpriv *p = (struct aiffpriv *) ft->priv;
-	int littlendian;
-	char *endptr;
 	int rc;
 
 	/* Needed because st_rawwrite() */
@@ -625,9 +620,7 @@
 
 	/* AIFF is in Big Endian format.  Swap whats read in on Little */
 	/* Endian machines.                                            */
-	littlendian = 1;
-	endptr = (char *) &littlendian;
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 	    ft->swap = ft->swap ? 0 : 1;
 	}
--- a/src/au.c
+++ b/src/au.c
@@ -117,8 +117,6 @@
 	char *buf;
 	struct aupriv *p = (struct aupriv *) ft->priv;
 
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 	/* Needed for rawread() */
@@ -126,11 +124,10 @@
 	if (rc)
 	    return rc;
 
-	endptr = (char *) &littlendian;
 	/* AU is in big endian format.  Swap whats read
 	 * in onlittle endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
@@ -242,8 +239,6 @@
 ft_t ft;
 {
 	struct aupriv *p = (struct aupriv *) ft->priv;
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 	/* Needed because of rawwrite(); */
@@ -251,11 +246,10 @@
 	if (rc)
 	    return rc;
 
-	endptr = (char *) &littlendian;
 	/* AU is in big endian format.  Swap whats read in
 	 * on little endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
--- a/src/avr.c
+++ b/src/avr.c
@@ -67,14 +67,11 @@
 ft_t ft;
 {
   avr_t	avr = (avr_t)ft->priv;
-  int littlendian = 1;
-  char *endptr;
   int rc;
 
   /* AVR is a Big Endian format.  Swap whats read in on Little */
   /* Endian machines.					       */
-  endptr = (char *) &littlendian;
-  if (*endptr)
+  if (ST_IS_LITTLEENDIAN)
   {
 	  ft->swap = ft->swap ? 0 : 1;
   }
@@ -156,14 +153,11 @@
 ft_t ft;
 {
   avr_t	avr = (avr_t)ft->priv;
-  int littlendian = 1;
-  char *endptr;
   int rc;
 
   /* AVR is a Big Endian format.  Swap whats read in on Little */
   /* Endian machines.					       */
-  endptr = (char *) &littlendian;
-  if (*endptr)
+  if (ST_IS_LITTLEENDIAN)
   {
 	  ft->swap = ft->swap ? 0 : 1;
   }
--- a/src/cdr.c
+++ b/src/cdr.c
@@ -42,9 +42,6 @@
 int st_cdrstartread(ft) 
 ft_t ft;
 {
-
-	int     littlendian = 1;
-	char    *endptr;
 	int rc;
 
 	/* Needed because of rawread() */
@@ -52,10 +49,9 @@
 	if (rc)
 	    return rc;
 
-	endptr = (char *) &littlendian;
 	/* CDR is in Big Endian format.  Swap whats read in on */
         /* Little Endian machines.                             */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{ 
 	    ft->swap = ft->swap ? 0 : 1;
 	}
@@ -99,15 +95,11 @@
 ft_t ft;
 {
 	cdr_t cdr = (cdr_t) ft->priv;
-
-	int     littlendian = 1;
-	char    *endptr;
 	int rc;
 
-	endptr = (char *) &littlendian;
 	/* CDR is in Big Endian format.  Swap whats written out on */
 	/* Little Endian Machines.                                 */
-	if (*endptr) 
+	if (ST_IS_LITTLEENDIAN)
 	{
 	    ft->swap = ft->swap ? 0 : 1;
 	}
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -58,17 +58,13 @@
 	ULONG datasize, rsrcsize;
 	ULONG huffcount, checksum, compresstype, divisor;
 	unsigned short dictsize;
-
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 
-	endptr = (char *) &littlendian;
 	/* hcom is in big endian format.  Swap whats
 	 * read in on little machine
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
@@ -282,14 +278,10 @@
 {
 	register struct writepriv *p = (struct writepriv *) ft->priv;
 
-	int littlendian = 1;
-	char *endptr;
-
-	endptr = (char *) &littlendian;
 	/* hcom is inbigendian format.  Swap whats
 	 * read in on little endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
--- a/src/maud.c
+++ b/src/maud.c
@@ -55,9 +55,6 @@
 	
 	ULONG chunksize;
 	ULONG trash;
-
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 	/* Needed for rawread() */
@@ -65,11 +62,10 @@
 	if (rc)
 	    return rc;
 
-	endptr = (char *) &littlendian;
 	/* maud is in big endian format.  Swap whats read in
 	 * on little endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
@@ -251,9 +247,6 @@
 ft_t ft;
 {
 	struct maudstuff * p = (struct maudstuff *) ft->priv;
-
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 	/* Needed for rawwrite() */
@@ -261,11 +254,10 @@
 	if (rc)
 	    return rc;
 
-	endptr = (char *) &littlendian;
 	/* maud is in big endian format.  Swap whats read in
 	 * on little endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -38,9 +38,6 @@
         char buf[97];
 
         unsigned short rate;
-
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 	/* Needed for rawread() */
@@ -48,11 +45,10 @@
 	if (rc)
 	    return rc;
 
-	endptr = (char *) &littlendian;
 	/* sndt is in little endian format so 
 	 * swap bytes on big endian machines.
 	 */
-	if (!*endptr)
+	if (ST_IS_BIGENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
@@ -116,9 +112,6 @@
 ft_t ft;
 {
 	struct sndpriv *p = (struct sndpriv *) ft->priv;
-
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 	/* Needed for rawwrite() */
@@ -126,11 +119,10 @@
 	if (rc)
 	    return rc;
 
-	endptr = (char *) &littlendian;
 	/* sndt is in little endian format so
 	 * swap bytes on big endian machines
 	 */
-	if (!*endptr)
+	if (ST_IS_BIGENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
--- a/src/st.h
+++ b/src/st.h
@@ -337,6 +337,17 @@
 void st_fail(P2(const char *, ...))NORET;
 void st_fail_errno(P4(ft_t, int, const char *, ...));
 
+int st_is_bigendian(void);
+int st_is_littleendian(void);
+
+#ifdef WORDS_BIGENDIAN
+#define ST_IS_BIGENDIAN 1
+#define ST_IS_LITTLEENDIAN 0
+#else
+#define ST_IS_BIGENDIAN st_is_bigendian()
+#define ST_IS_LITTLEENDIAN st_is_littleendian()
+#endif
+
 int st_geteffect_opt(P3(eff_t, int, char **));
 int st_geteffect(P2(eff_t, char *));
 int st_updateeffect(P4(eff_t, ft_t, ft_t, int));
--- a/src/util.c
+++ b/src/util.c
@@ -98,6 +98,32 @@
 	va_end(args);
 }
 
+int st_is_bigendian(void)
+{
+    int b;
+    char *p;
+
+    b = 1;
+    p = (char *) &b;
+    if (!*p)
+	return 1;
+    else
+	return 0;
+}
+
+int st_is_littleendian(void)
+{
+    int b;
+    char *p;
+
+    b = 1;
+    p = (char *) &b;
+    if (*p)
+	return 1;
+    else
+	return 0;
+}
+
 int strcmpcase(s1, s2)
 char *s1, *s2;
 {
--- a/src/voc.c
+++ b/src/voc.c
@@ -177,14 +177,11 @@
 	char header[20];
 	vs_t v = (vs_t) ft->priv;
 	unsigned short sbseek;
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
-	endptr = (char *) &littlendian;
 	/* VOC is in Little Endian format.  Swap bytes read in on */
 	/* Big Endian mahcines.				          */
-	if (!*endptr)
+	if (ST_IS_BIGENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
@@ -306,13 +303,10 @@
 ft_t ft;
 {
 	vs_t v = (vs_t) ft->priv;
-	int littlendian = 1;
-	char *endptr;
 
-	endptr = (char *) &littlendian;
 	/* VOC is in Little Endian format.  Swap whats read */
 	/* in on Big Endian machines.			    */
-	if (!*endptr)
+	if (ST_IS_BIGENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
--- a/src/wav.c
+++ b/src/wav.c
@@ -442,8 +442,6 @@
     wav_t	wav = (wav_t) ft->priv;
     char	magic[5];
     ULONG	len;
-    int		littlendian = 1;
-    char	*endptr;
     int		rc;
 
     /* wave file characteristics */
@@ -459,8 +457,7 @@
     ULONG    bytesPerBlock = 0;
     ULONG    bytespersample;	    /* bytes per sample (per channel */
 
-    endptr = (char *) &littlendian;
-    if (!*endptr) ft->swap = ft->swap ? 0 : 1;
+    if (ST_IS_BIGENDIAN) ft->swap = ft->swap ? 0 : 1;
 
     if (st_reads(ft, magic, 4) == ST_EOF || strncmp("RIFF", magic, 4))
     {
@@ -1037,12 +1034,9 @@
 ft_t ft;
 {
 	wav_t	wav = (wav_t) ft->priv;
-	int	littlendian = 1;
-	char	*endptr;
 	int	rc;
 
-	endptr = (char *) &littlendian;
-	if (!*endptr) ft->swap = ft->swap ? 0 : 1;
+	if (ST_IS_BIGENDIAN) ft->swap = ft->swap ? 0 : 1;
 
 	wav->numSamples = 0;
 	wav->dataLength = 0;
--- a/src/wve.c
+++ b/src/wve.c
@@ -28,9 +28,6 @@
 	struct wvepriv *p = (struct wvepriv *) ft->priv;
 	char magic[16];
 	short version;
-
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 	ULONG trash;
@@ -40,11 +37,10 @@
 	if (rc)
 	    return rc;
 
-	endptr = (char *) &littlendian;
 	/* WVE is in big endian format.  Swap whats read in
 	 * on little endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
@@ -114,9 +110,6 @@
 ft_t ft;
 {
 	struct wvepriv *p = (struct wvepriv *) ft->priv;
-
-	int littlendian = 1;
-	char *endptr;
 	int rc;
 
 	/* Needed for rawwrite() */
@@ -124,11 +117,10 @@
 	if (rc)
 	    return ST_EOF;
 
-	endptr = (char *) &littlendian;
 	/* wve is in big endian format.  Swap whats read in
 	 * on little endian machines.
 	 */
-	if (*endptr)
+	if (ST_IS_LITTLEENDIAN)
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}