[matio] fix build on big endian platforms
Dan Horák
sharkcz at fedoraproject.org
Wed Jan 9 18:23:47 UTC 2013
commit 4d7b38a65b814314fde145bc3593c911a0a795c1
Author: Dan Horák <dan at danny.cz>
Date: Wed Jan 9 19:23:41 2013 +0100
fix build on big endian platforms
matio-1.5.0-big-endian.patch | 54 ++++++++++++++++++++++++++++++++++++++++++
matio.spec | 7 ++++-
2 files changed, 60 insertions(+), 1 deletions(-)
---
diff --git a/matio-1.5.0-big-endian.patch b/matio-1.5.0-big-endian.patch
new file mode 100644
index 0000000..53f5032
--- /dev/null
+++ b/matio-1.5.0-big-endian.patch
@@ -0,0 +1,54 @@
+From: Christopher Hulbert <chulbe2lsu at users.sourceforge.net>
+Date: Thu, 20 Dec 2012 17:29:04 +0000 (-0500)
+Subject: Fix endian check for v4 MAT files and big-endian systems
+X-Git-Url: http://matio.git.sourceforge.net/git/gitweb.cgi?p=matio%2Fmatio;a=commitdiff_plain;h=3b91a84c6f6ab5e401df18b5b0589bedce42df6a;hp=09f5c87438a5883361b38cc98b4848acfcb65d97
+
+Fix endian check for v4 MAT files and big-endian systems
+
+* src/mat4.c (Mat_VarReadNextInfo4): Check endianness of host computer and
+ compare to the M part of the variable type to determine if
+ byteswapping is required
+---
+
+diff --git a/src/mat4.c b/src/mat4.c
+index bf2aaae..b1d7194 100644
+--- a/src/mat4.c
++++ b/src/mat4.c
+@@ -193,6 +193,10 @@ Mat_VarReadNextInfo4(mat_t *mat)
+ long nBytes;
+ size_t err;
+ matvar_t *matvar = NULL;
++ union {
++ mat_uint32_t u;
++ mat_uint8_t c[4];
++ } endian;
+
+ if ( mat == NULL || mat->fp == NULL )
+ return NULL;
+@@ -208,6 +212,8 @@ Mat_VarReadNextInfo4(mat_t *mat)
+ return NULL;
+ }
+
++ endian.u = 0x01020304;
++
+ /* See if MOPT may need byteswapping */
+ if ( tmp < 0 || tmp > 4052 ) {
+ if ( Mat_int32Swap(&tmp) > 4052 ) {
+@@ -224,7 +230,16 @@ Mat_VarReadNextInfo4(mat_t *mat)
+ tmp -= data_type*10;
+ class_type = floor(tmp);
+
+- mat->byteswap = (M == 1) ? 1 : 0;
++ switch ( M ) {
++ case 0:
++ /* IEEE little endian */
++ mat->byteswap = (endian.c[0] != 4);
++ break;
++ case 1:
++ /* IEEE big endian */
++ mat->byteswap = (endian.c[0] != 1);
++ break;
++ }
+ /* Convert the V4 data type */
+ switch ( data_type ) {
+ case 0:
diff --git a/matio.spec b/matio.spec
index 046192e..857756d 100644
--- a/matio.spec
+++ b/matio.spec
@@ -1,12 +1,13 @@
Name: matio
Version: 1.5.0
-Release: 4%{?dist}
+Release: 5%{?dist}
Summary: Library for reading/writing Matlab MAT files
Group: System Environment/Libraries
License: BSD
URL: http://sourceforge.net/projects/matio
Source0: http://downloads.sourceforge.net/matio/matio-%{version}.tar.gz
+Patch0: %{name}-1.5.0-big-endian.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: doxygen
@@ -37,6 +38,7 @@ developing applications that use %{name}.
%prep
%setup -q
+%patch0 -p1 -b .big-endian
%build
@@ -94,6 +96,9 @@ rm -rf $RPM_BUILD_ROOT
%changelog
+* Wed Jan 09 2013 Dan Horák <dan[at]danny.cz> - 1.5.0-5
+- fix build on big endian platforms
+
* Wed Dec 05 2012 Orion Poplawski <orion at cora.nwra.com> - 1.5.0-4
- Rebuild for hdf5 1.8.10
More information about the scm-commits
mailing list