Mercurial > hg > octave-nkf
changeset 1415:f18474c64e72
[project @ 1995-09-15 10:09:57 by jwe]
author | jwe |
---|---|
date | Fri, 15 Sep 1995 10:13:17 +0000 |
parents | 88ba3aed5697 |
children | 8b976f7c0aa8 |
files | configure.in src/load-save.cc src/sysdep.cc |
diffstat | 3 files changed, 26 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.in +++ b/configure.in @@ -20,7 +20,7 @@ ### along with Octave; see the file COPYING. If not, write to the Free ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -AC_REVISION($Revision: 1.135 $) +AC_REVISION($Revision: 1.136 $) AC_PREREQ(2.0) AC_INIT(src/octave.cc) AC_CONFIG_HEADER(config.h) @@ -371,7 +371,6 @@ AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) -AC_C_BIGENDIAN ### Does the C compiler handle alloca() and const correctly?
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -1698,10 +1698,8 @@ // // Gag me. -#if defined (WORDS_BIGENDIAN) - if (mopt == 0) + if (octave_words_big_endian && mopt == 0) swap = 1; -#endif // mopt is signed, therefore byte swap may result in negative value. @@ -1903,21 +1901,9 @@ is.read (magic, magic_len); magic[magic_len] = '\0'; if (strncmp (magic, "Octave-1-L", magic_len) == 0) - { -#if defined (WORDS_BIGENDIAN) - swap = 1; -#else - swap = 0; -#endif - } + swap = octave_words_big_endian; else if (strncmp (magic, "Octave-1-B", magic_len) == 0) - { -#if defined (WORDS_BIGENDIAN) - swap = 0; -#else - swap = 1; -#endif - } + swap = ! octave_words_big_endian; else { if (! quiet) @@ -2859,11 +2845,7 @@ { if (format == LS_BINARY) { -#if defined (WORDS_BIGENDIAN) - stream << "Octave-1-B"; -#else - stream << "Octave-1-L"; -#endif + stream << (octave_words_big_endian ? "Octave-1-B" : "Octave-1-L"); char tmp = (char) native_float_format; stream.write (&tmp, 1);
--- a/src/sysdep.cc +++ b/src/sysdep.cc @@ -89,6 +89,9 @@ // The floating point format on this system. floating_point_format native_float_format = OCTAVE_UNKNOWN_FLT_FMT; +// Nonzero if the machine we are running on is big-endian. +int octave_words_big_endian; + #if defined (HAVE_FLOATINGPOINT_H) #include <floatingpoint.h> #endif @@ -249,6 +252,22 @@ panic ("unrecognized floating point format!"); } +static void +ten_little_endians (void) +{ + // Are we little or big endian? From Harbison & Steele. + + union + { + long l; + char c[sizeof (long)]; + } u; + + u.l = 1; + + octave_words_big_endian = (u.c[sizeof (long) - 1] == 1); +} + #if defined (EXCEPTION_IN_MATH) extern "C" { @@ -292,6 +311,8 @@ #endif octave_ieee_init (); + + ten_little_endians (); } // Set terminal in raw mode. From less-177.