@@ -906,8 +906,33 @@ int VSIFFlushL( VSILFILE* fp );
906906
907907VSI_RETVAL VSIFCloseL ( VSILFILE* fp );
908908
909+ // Wrap VSIFSeekL to allow negative offsets
910+ %rename (VSIFSeekL) wrapper_VSIFSeekL;
911+ %inline {
912+ #if defined(SWIGPYTHON)
913+ int wrapper_VSIFSeekL ( VSILFILE* fp, GIntBig offset, int whence) {
914+ #else
915+ VSI_RETVAL VSIFSeekL ( VSILFILE* fp, long offset, int whence) {
916+ #endif
917+ if (offset < 0 ) {
918+ switch (whence) {
919+ case SEEK_END: VSIFSeekL (fp, 0 , SEEK_END);
920+ case SEEK_CUR:
921+ offset = VSIFTellL (fp) + offset;
922+ whence = SEEK_SET;
923+ break ;
924+ default :
925+ VSIError (VSIE_FileError, " Cannot use negative offset with SEEK_SET" );
926+ return -1 ;
927+ }
928+ }
929+
930+ return VSIFSeekL (fp, offset, whence);
931+ }
932+ }
933+
934+
909935#if defined(SWIGPYTHON)
910- int VSIFSeekL ( VSILFILE* fp, GIntBig offset, int whence);
911936GIntBig VSIFTellL ( VSILFILE* fp );
912937int VSIFTruncateL ( VSILFILE* fp, GIntBig length );
913938
@@ -919,7 +944,6 @@ int VSISupportsSparseFiles( const char* utf8_path );
919944
920945int VSIFGetRangeStatusL ( VSILFILE* fp, GIntBig offset, GIntBig length );
921946#else
922- VSI_RETVAL VSIFSeekL ( VSILFILE* fp, long offset, int whence);
923947long VSIFTellL ( VSILFILE* fp );
924948VSI_RETVAL VSIFTruncateL ( VSILFILE* fp, long length );
925949#endif
0 commit comments