Use inttypes.h specified types. This is the standard and fixes some 64-bit problems.

This commit is contained in:
ehofman
2005-09-15 17:06:31 +00:00
parent 9dfd6970f1
commit b1b6abf285
3 changed files with 27 additions and 32 deletions

View File

@@ -81,7 +81,7 @@ void sgReadDouble ( gzFile fd, double *var )
read_error = true ;
}
if ( sgIsBigEndian() ) {
sgEndianSwap( (uint64*)var);
sgEndianSwap( (uint64_t*)var);
}
}
@@ -89,7 +89,7 @@ void sgReadDouble ( gzFile fd, double *var )
void sgWriteDouble ( gzFile fd, const double var )
{
if ( sgIsBigEndian() ) {
sgEndianSwap( (uint64*)&var);
sgEndianSwap( (uint64_t*)&var);
}
if ( gzwrite ( fd, (void *)(&var), sizeof(double) ) != sizeof(double) ) {
write_error = true ;
@@ -143,9 +143,9 @@ void sgWriteInt ( gzFile fd, const int var )
}
void sgReadLong ( gzFile fd, long int *var )
void sgReadLong ( gzFile fd, int32_t *var )
{
if ( gzread ( fd, var, sizeof(long int) ) != sizeof(long int) ) {
if ( gzread ( fd, var, sizeof(int32_t) ) != sizeof(int32_t) ) {
read_error = true ;
}
if ( sgIsBigEndian() ) {
@@ -154,37 +154,37 @@ void sgReadLong ( gzFile fd, long int *var )
}
void sgWriteLong ( gzFile fd, const long int var )
void sgWriteLong ( gzFile fd, const int32_t var )
{
if ( sgIsBigEndian() ) {
sgEndianSwap( (unsigned int*)&var);
}
if ( gzwrite ( fd, (void *)(&var), sizeof(long int) )
!= sizeof(long int) )
if ( gzwrite ( fd, (void *)(&var), sizeof(int32_t) )
!= sizeof(int32_t) )
{
write_error = true ;
}
}
void sgReadLongLong ( gzFile fd, int64 *var )
void sgReadLongLong ( gzFile fd, int64_t *var )
{
if ( gzread ( fd, var, sizeof(int64) ) != sizeof(int64) ) {
if ( gzread ( fd, var, sizeof(int64_t) ) != sizeof(int64_t) ) {
read_error = true ;
}
if ( sgIsBigEndian() ) {
sgEndianSwap( (uint64*)var);
sgEndianSwap( (uint64_t*)var);
}
}
void sgWriteLongLong ( gzFile fd, const int64 var )
void sgWriteLongLong ( gzFile fd, const int64_t var )
{
if ( sgIsBigEndian() ) {
sgEndianSwap( (uint64*)&var);
sgEndianSwap( (uint64_t*)&var);
}
if ( gzwrite ( fd, (void *)(&var), sizeof(int64) )
!= sizeof(int64) )
if ( gzwrite ( fd, (void *)(&var), sizeof(int64_t) )
!= sizeof(int64_t) )
{
write_error = true ;
}
@@ -275,7 +275,7 @@ void sgReadDouble ( gzFile fd, const unsigned int n, double *var )
}
if ( sgIsBigEndian() ) {
for ( unsigned int i = 0; i < n; ++i ) {
sgEndianSwap( (uint64*)var++);
sgEndianSwap( (uint64_t*)var++);
}
}
}
@@ -288,7 +288,7 @@ void sgWriteDouble ( gzFile fd, const unsigned int n, const double *var )
double *ptr = swab;
memcpy( swab, var, sizeof(double) * n );
for ( unsigned int i = 0; i < n; ++i ) {
sgEndianSwap( (uint64*)ptr++);
sgEndianSwap( (uint64_t*)ptr++);
}
var = swab;
}

View File

@@ -29,17 +29,12 @@
#include <stdio.h>
#include <inttypes.h>
#include <zlib.h>
#include <plib/sg.h>
#ifdef _MSC_VER
typedef __int64 int64;
typedef __int64 uint64;
#else
typedef long long int64;
typedef unsigned long long uint64;
#endif
#include <simgear/compiler.h>
// Note that output is written in little endian form (and converted as
// necessary for big endian machines)
@@ -54,10 +49,10 @@ void sgReadUInt ( gzFile fd, unsigned int *var ) ;
void sgWriteUInt ( gzFile fd, const unsigned int var ) ;
void sgReadInt ( gzFile fd, int *var ) ;
void sgWriteInt ( gzFile fd, const int var ) ;
void sgReadLong ( gzFile fd, long int *var ) ;
void sgWriteLong ( gzFile fd, const long int var ) ;
void sgReadLongLong ( gzFile fd, int64 *var ) ;
void sgWriteLongLong ( gzFile fd, const int64 var ) ;
void sgReadLong ( gzFile fd, int32_t *var ) ;
void sgWriteLong ( gzFile fd, const int32_t var ) ;
void sgReadLongLong ( gzFile fd, int64_t *var ) ;
void sgWriteLongLong ( gzFile fd, const int64_t var ) ;
void sgReadUShort ( gzFile fd, unsigned short *var ) ;
void sgWriteUShort ( gzFile fd, const unsigned short var ) ;
void sgReadShort ( gzFile fd, short *var ) ;
@@ -145,7 +140,7 @@ inline void sgEndianSwap(unsigned int *x) {
(( *x << 24 ) & 0xFF000000 ) ;
}
inline void sgEndianSwap(uint64 *x) {
inline void sgEndianSwap(uint64_t *x) {
#ifndef _MSC_VER
*x =
(( *x >> 56 ) & 0x00000000000000FFULL ) |

View File

@@ -403,9 +403,9 @@ bool SGBinObject::read_bin( const string& file ) {
double *dptr = (double *)ptr;
if ( sgIsBigEndian() ) {
sgEndianSwap( (uint64 *)&(dptr[0]) );
sgEndianSwap( (uint64 *)&(dptr[1]) );
sgEndianSwap( (uint64 *)&(dptr[2]) );
sgEndianSwap( (uint64_t *)&(dptr[0]) );
sgEndianSwap( (uint64_t *)&(dptr[1]) );
sgEndianSwap( (uint64_t *)&(dptr[2]) );
}
gbs_center = Point3D( dptr[0], dptr[1], dptr[2] );
// cout << "Center = " << gbs_center << endl;
@@ -656,7 +656,7 @@ bool SGBinObject::write_bin( const string& base, const string& name,
// write header magic
sgWriteUInt( fp, SG_FILE_MAGIC_NUMBER );
time_t calendar_time = time(NULL);
sgWriteLong( fp, (long int)calendar_time );
sgWriteLong( fp, (int32_t)calendar_time );
// calculate and write number of top level objects
string material;