[segyio] 48/376: Replace non-conditional flipEndianness with htonl
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
jokva-guest pushed a commit to branch debian
in repository segyio.
commit e97ac60263f3d27f84bab8d2b0b0dd448607b709
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date: Mon Oct 17 17:32:03 2016 +0200
Replace non-conditional flipEndianness with htonl
---
src/segyio/segy.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/src/segyio/segy.c b/src/segyio/segy.c
index 9bd1ec6..8f8d841 100644
--- a/src/segyio/segy.c
+++ b/src/segyio/segy.c
@@ -6,6 +6,7 @@
#include <winsock2.h>
#endif
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
@@ -153,17 +154,6 @@ void ieee2ibm(void* to, const void* from, int len) {
}
}
-static void flipEndianness32(char* data, unsigned int count) {
- for( unsigned int i = 0; i < count; i += 4) {
- char a = data[i];
- char b = data[i + 1];
- data[i] = data[i + 3];
- data[i + 1] = data[i + 2];
- data[i + 2] = b;
- data[i + 3] = a;
- }
-}
-
/* Lookup table for field sizes. All values not explicitly set are 0 */
static int field_size[] = {
[CDP] = 4,
@@ -900,8 +890,16 @@ int segy_to_native( int format,
unsigned int size,
float* buf ) {
- if( format == IEEE_FLOAT_4_BYTE )
- flipEndianness32( (char*)buf, size * sizeof( float ) );
+ assert( sizeof( float ) == sizeof( uint32_t ) );
+
+ if( format == IEEE_FLOAT_4_BYTE ) {
+ uint32_t u;
+ while( size-- ) {
+ memcpy( &u, buf, sizeof( float ) );
+ u = ntohl( u );
+ memcpy( buf++, &u, sizeof( float ) );
+ }
+ }
else
ibm2ieee( buf, buf, size );
@@ -912,8 +910,16 @@ int segy_from_native( int format,
unsigned int size,
float* buf ) {
- if( format == IEEE_FLOAT_4_BYTE )
- flipEndianness32( (char*)buf, size * sizeof( float ) );
+ assert( sizeof( float ) == sizeof( uint32_t ) );
+
+ if( format == IEEE_FLOAT_4_BYTE ) {
+ uint32_t u;
+ while( size-- ) {
+ memcpy( &u, buf, sizeof( float ) );
+ u = htonl( u );
+ memcpy( buf++, &u, sizeof( float ) );
+ }
+ }
else
ieee2ibm( buf, buf, size );
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git
More information about the debian-science-commits
mailing list