aports/testing/gdcm/30-off_t.patch
Holger Jaekel 27b9a80f17 testing/gdcm: new aport
http://gdcm.sourceforge.net
Grassroots DiCoM is a C++ library for DICOM medical files
2023-11-03 02:14:26 +00:00

211 lines
6.9 KiB
Diff

--- a/Source/MediaStorageAndFileFormat/gdcmFileStreamer.cxx
+++ b/Source/MediaStorageAndFileFormat/gdcmFileStreamer.cxx
@@ -49,7 +49,7 @@
// http://stackoverflow.com/questions/17863594/size-of-off-t-at-compilation-time
// Basically enforce use of off64_t over off_t since on windows off_t is pretty
// much guarantee to be 32bits only.
-static inline int FSeeko(FILE *stream, off64_t offset, int whence)
+static inline int FSeeko(FILE *stream, off_t offset, int whence)
{
#if _WIN32
#if defined(__MINGW32__)
@@ -62,7 +62,7 @@
#endif
}
-static inline off64_t FTello(FILE *stream)
+static inline off_t FTello(FILE *stream)
{
#if _WIN32
#if defined(__MINGW32__)
@@ -75,7 +75,7 @@
#endif
}
-static inline bool FTruncate( const int fd, const off64_t len )
+static inline bool FTruncate( const int fd, const off_t len )
{
#if _WIN32
#if defined(__MINGW32__)
@@ -93,7 +93,7 @@
#endif
}
-static bool prepare_file( FILE * pFile, const off64_t offset, const off64_t inslen )
+static bool prepare_file( FILE * pFile, const off_t offset, const off_t inslen )
{
// fast path
if( inslen == 0 ) return true;
@@ -108,13 +108,13 @@
{
if( inslen < 0 )
{
- off64_t bytes_to_move = sb.st_size - offset;
- off64_t read_start_offset = offset;
+ off_t bytes_to_move = sb.st_size - offset;
+ off_t read_start_offset = offset;
while (bytes_to_move != 0)
{
- const size_t bytes_this_time = static_cast<size_t>(std::min((off64_t)BUFFERSIZE, bytes_to_move));
- const off64_t rd_off = read_start_offset;
- const off64_t wr_off = rd_off + inslen;
+ const size_t bytes_this_time = static_cast<size_t>(std::min((off_t)BUFFERSIZE, bytes_to_move));
+ const off_t rd_off = read_start_offset;
+ const off_t wr_off = rd_off + inslen;
if( FSeeko(pFile, rd_off, SEEK_SET) )
{
return false;
@@ -148,14 +148,14 @@
#endif
if (sb.st_size > offset)
{
- off64_t bytes_to_move = sb.st_size - offset;
- off64_t read_end_offset = sb.st_size;
+ off_t bytes_to_move = sb.st_size - offset;
+ off_t read_end_offset = sb.st_size;
while (bytes_to_move != 0)
{
- const size_t bytes_this_time = static_cast<size_t>(std::min((off64_t)BUFFERSIZE, bytes_to_move));
- const off64_t rd_off = read_end_offset - bytes_this_time;
- assert( (off64_t)rd_off >= offset );
- const off64_t wr_off = rd_off + inslen;
+ const size_t bytes_this_time = static_cast<size_t>(std::min((off_t)BUFFERSIZE, bytes_to_move));
+ const off_t rd_off = read_end_offset - bytes_this_time;
+ assert( (off_t)rd_off >= offset );
+ const off_t wr_off = rd_off + inslen;
if( FSeeko(pFile, rd_off, SEEK_SET) )
{
return false;
@@ -326,15 +326,15 @@
size_t dicomlen = 4 + 4; // Tag + VL for Implicit
if( TS.GetNegociatedType() == TransferSyntax::Explicit )
dicomlen += 4;
- off64_t newlen = len;
+ off_t newlen = len;
assert( (size_t)newlen == len );
newlen += dicomlen;
newlen -= actualde;
- off64_t plength = newlen;
+ off_t plength = newlen;
assert( ReservedDataLength >= 0 );
if( ReservedDataLength )
{
- if( (newlen + ReservedDataLength) >= (off64_t)len )
+ if( (newlen + ReservedDataLength) >= (off_t)len )
{
plength = newlen + ReservedDataLength - len;
}
@@ -345,8 +345,8 @@
ReservedDataLength -= len;
assert( ReservedDataLength >= 0 );
}
- //if( !prepare_file( pFile, (off64_t)thepos + actualde, newlen ) )
- if( !prepare_file( pFile, (off64_t)thepos + actualde, plength ) )
+ //if( !prepare_file( pFile, (off_t)thepos + actualde, newlen ) )
+ if( !prepare_file( pFile, (off_t)thepos + actualde, plength ) )
{
return false;
}
@@ -360,18 +360,18 @@
else
{
assert( pFile );
- const off64_t curpos = FTello(pFile);
+ const off_t curpos = FTello(pFile);
assert( curpos == thepos );
- if( ReservedDataLength >= (off64_t)len )
+ if( ReservedDataLength >= (off_t)len )
{
// simply update remaining reserved buffer:
ReservedDataLength -= len;
}
else
{
- const off64_t plength = len - ReservedDataLength;
+ const off_t plength = len - ReservedDataLength;
assert( plength >= 0 );
- if( !prepare_file( pFile, (off64_t)curpos, plength) )
+ if( !prepare_file( pFile, (off_t)curpos, plength) )
{
return false;
}
@@ -392,14 +392,14 @@
// Update DataElement:
const size_t currentdatalenth = CurrentDataLenth;
assert( ReservedDataLength >= 0);
- //const off64_t refpos = FTello(pFile);
+ //const off_t refpos = FTello(pFile);
if( !UpdateDataElement( t ) )
{
return false;
}
if( ReservedDataLength > 0)
{
- const off64_t curpos = thepos;
+ const off_t curpos = thepos;
if( !prepare_file( pFile, curpos + ReservedDataLength, - ReservedDataLength) )
{
return false;
@@ -584,7 +584,7 @@
pFile = fopen(outfilename, "r+b");
assert( pFile );
- if( !prepare_file( pFile, (off64_t)thepcpos, pclen ) )
+ if( !prepare_file( pFile, (off_t)thepcpos, pclen ) )
{
return false;
}
@@ -670,7 +670,7 @@
size_t actualde;
size_t CurrentDataLenth;
Tag CurrentGroupTag;
- off64_t ReservedDataLength{0};
+ off_t ReservedDataLength{0};
unsigned short ReservedGroupDataElement{0};
public:
FileStreamer *Self{nullptr};
@@ -682,7 +682,7 @@
{
if( CurrentDataLenth % 2 == 1 )
{
- const off64_t curpos = FTello(pFile);
+ const off_t curpos = FTello(pFile);
if( ReservedDataLength >= 1 )
{
// simply update remaining reserved buffer:
@@ -690,7 +690,7 @@
}
else
{
- if( !prepare_file( pFile, (off64_t)curpos, 1) )
+ if( !prepare_file( pFile, (off_t)curpos, 1) )
{
return false;
}
@@ -702,7 +702,7 @@
CurrentDataLenth += 1;
}
assert( CurrentDataLenth % 2 == 0 );
- off64_t vlpos = thepos;
+ off_t vlpos = thepos;
vlpos -= CurrentDataLenth;
vlpos -= 4; // VL
if( TS.GetNegociatedType() == TransferSyntax::Explicit )
@@ -720,7 +720,7 @@
}
return true;
}
- size_t WriteHelper( off64_t offset, const Tag & tag, const VL & vl )
+ size_t WriteHelper( off_t offset, const Tag & tag, const VL & vl )
{
FSeeko(pFile, offset, SEEK_SET);
std::stringstream ss;
@@ -765,7 +765,7 @@
static int checksize = 0;
if( !checksize )
{
- const int soff = sizeof( off64_t );
+ const int soff = sizeof( off_t );
const int si64 = sizeof( int64_t );
if( soff != si64 ) return false;
if( !(sizeof(sb.st_size) > 4) ) // LFS ?