[segyio] 230/376: Preprocessor switch on long<longlong code path

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:38 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 d0a245a4e58939d486442d3d346999d2868b5d54
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date:   Tue Mar 7 09:51:03 2017 +0100

    Preprocessor switch on long<longlong code path
    
    The test is now guaranteed to be compile time, and the slow path will
    never be taken on a platform where long is sufficiently large to
    represent all byte offsets in the file.
---
 lib/src/segy.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/lib/src/segy.c b/lib/src/segy.c
index 75783fd..6f3363d 100644
--- a/lib/src/segy.c
+++ b/lib/src/segy.c
@@ -639,24 +639,26 @@ int segy_seek( segy_file* fp,
     }
 
     int err = SEGY_OK;
-    if( sizeof( long ) == sizeof( long long ) ) {
-        err = fseek( fp->fp, pos, SEEK_SET );
-    } else {
-        /*
-         * If long is 32bit on our platform (hello, windows), we do skips according
-         * to LONG_MAX and seek relative to our cursor rather than absolute on file
-         * begin.
-         */
-        rewind( fp->fp );
-        while( pos >= LONG_MAX && err == SEGY_OK ) {
-            err = fseek( fp->fp, LONG_MAX, SEEK_CUR );
-            pos -= LONG_MAX;
-        }
+#if LONG_MAX == LLONG_MAX
+    assert( pos <= LONG_MAX );
+    err = fseek( fp->fp, (long)pos, SEEK_SET );
+#else
+   /*
+    * If long is 32bit on our platform (hello, windows), we do skips according
+    * to LONG_MAX and seek relative to our cursor rather than absolute on file
+    * begin.
+    */
+    rewind( fp->fp );
+    while( pos >= LONG_MAX && err == SEGY_OK ) {
+        err = fseek( fp->fp, LONG_MAX, SEEK_CUR );
+        pos -= LONG_MAX;
+    }
 
-        if( err != 0 ) return SEGY_FSEEK_ERROR;
+    if( err != 0 ) return SEGY_FSEEK_ERROR;
 
-        err = fseek( fp->fp, pos, SEEK_CUR );
-    }
+    assert( pos <= LONG_MAX );
+    err = fseek( fp->fp, (long)pos, SEEK_CUR );
+#endif
 
     if( err != 0 ) return SEGY_FSEEK_ERROR;
     return SEGY_OK;

-- 
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