[R-gregmisc-users] SF.net SVN: r-gregmisc:[1845] trunk/SASxport/src/host_to_be.c
Brought to you by:
warnes
From: <wa...@us...> - 2014-07-19 03:37:14
|
Revision: 1845 http://sourceforge.net/p/r-gregmisc/code/1845 Author: warnes Date: 2014-07-19 03:37:05 +0000 (Sat, 19 Jul 2014) Log Message: ----------- Change byte-order detection code Modified Paths: -------------- trunk/SASxport/src/host_to_be.c Modified: trunk/SASxport/src/host_to_be.c =================================================================== --- trunk/SASxport/src/host_to_be.c 2014-07-19 03:31:00 UTC (rev 1844) +++ trunk/SASxport/src/host_to_be.c 2014-07-19 03:37:05 UTC (rev 1845) @@ -9,26 +9,31 @@ /* host_to_be: convert current host byte order to big endian */ void host_to_be( unsigned char *intp, size_t size) { - static unsigned char endianTest[2] = {0x01,0x00}; size_t i; unsigned char tmp; + short twobytes = 0x0001; + char onebyte = *(char*) &twobytes; + /* Test if we are on a big endian or little endian platform */ - if( (short) *endianTest != 1 ) + if (onebyte == 1) + { + /* Native byte order is little endian, so swap bytes */ + /* printf("Little Endian Machine!\n"); */ + + for(i=0; i < size/2; i++) + { + tmp = (unsigned char) intp[i]; + intp[i] = intp[size-i-1]; + intp[size-i-1] = tmp; + } + } + else { /* The native byte order is big endian, so do nothing */ - //printf("Big Endian Machine!\n"); - return; + /* printf("Big Endian Machine!\n"); */ } - - /* If native byte order is little endian, we need to swap bytes */ - for(i=0; i < size/2; i++) - { - tmp = (unsigned char) intp[i]; - intp[i] = intp[size-i-1]; - intp[size-i-1] = tmp; - } - + return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |