Changeset 3193


Ignore:
Timestamp:
12/16/07 13:42:19 (11 years ago)
Author:
paulf
Message:

made swap functions long int tolerant where in some OS, long can be 8 bytes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libsrc/util/swap.c

    r1867 r3193  
    88 *    Revision history: 
    99 *     $Log$ 
     10 *     Revision 1.11  2007/12/16 18:42:19  paulf 
     11 *     made swap functions long int tolerant where in some OS, long can be 8 bytes 
     12 * 
    1013 *     Revision 1.10  2005/06/13 18:15:41  dietz 
    1114 *     Changed logging for bad header values in WaveMsg2MakeLocal() to include 
     
    6770#endif  
    6871 
     72#include <stdio.h> 
     73#include <stdlib.h> 
    6974#include <string.h> 
    7075#include <swap.h> 
     
    113118      char c[4]; 
    114119   } dat; 
     120 
     121   if (sizeof(long) == 8) { 
     122      fprintf(stderr, "FATAL ERROR: SwapLong() assumes 4 byte longs and sizeof(long)=%d\n", sizeof(long)); 
     123      exit(9); 
     124   } 
    115125 
    116126   memcpy( &dat, data, sizeof(long) ); 
     
    181191   int    dataSize;  /* flag telling us how many bytes in the data */ 
    182192   char   byteOrder; 
    183    long*  longPtr; 
     193   int*   intPtr; 
    184194   short* shortPtr; 
    185195   int    i; 
     
    282292   { 
    283293   /* Swap the data.  */ 
    284         longPtr=(long*) ((char*)wvmsg + sizeof(TRACE2_HEADER) ); 
     294        intPtr=(int*) ((char*)wvmsg + sizeof(TRACE2_HEADER) ); 
    285295        shortPtr=(short*) ((char*)wvmsg + sizeof(TRACE2_HEADER) ); 
    286296        for( i=0; i<nsamp; i++) 
    287297        { 
    288298                if(dataSize==2) SwapShort( &(shortPtr[i]) ); 
    289                 if(dataSize==4) SwapLong(  &(longPtr[i])  ); 
     299                if(dataSize==4) SwapInt(  &(intPtr[i])  ); 
    290300        } 
    291301        /* Re-write the data type field in the message 
     
    300310   { 
    301311   /* Swap the data.  */ 
    302         longPtr=(long*) ((char*)wvmsg + sizeof(TRACE2_HEADER) ); 
     312        intPtr=(int*) ((char*)wvmsg + sizeof(TRACE2_HEADER) ); 
    303313        shortPtr=(short*) ((char*)wvmsg + sizeof(TRACE2_HEADER) ); 
    304314        for( i=0; i<nsamp; i++) 
    305315        { 
    306316                if(dataSize==2) SwapShort( &(shortPtr[i]) ); 
    307                 if(dataSize==4) SwapLong(  &(longPtr[i])  ); 
     317                if(dataSize==4) SwapInt(  &(intPtr[i])  ); 
    308318        } 
    309319        /* Re-write the data type field in the message 
Note: See TracChangeset for help on using the changeset viewer.