Doxygen Source Code Documentation
niml_byteorder.c File Reference
#include "niml_private.h"Go to the source code of this file.
| Data Structures | |
| struct | eightbytes | 
| struct | fourbytes | 
| struct | twobytes | 
| Functions | |
| int | NI_byteorder (void) | 
| void | NI_swap2 (int n, void *ar) | 
| void | NI_swap4 (int n, void *ar) | 
| void | NI_swap8 (int n, void *ar) | 
Function Documentation
| 
 | 
| Find the byte order on this system. Return is either NI_LSB_FIRST or NI_MSB_FIRST. We are assuming that there are only 2 possible order, which is of course false. ----------------------------------------------------------------- Definition at line 14 of file niml_byteorder.c. References NI_LSB_FIRST, and NI_MSB_FIRST. Referenced by NI_read_element(), NI_write_element(), and THD_write_1D(). 
 00015 {
00016    union { unsigned char bb[2] ;
00017            short         ss    ; } fred ;
00018 
00019    fred.bb[0] = 1 ; fred.bb[1] = 0 ;
00020 
00021    return (fred.ss == 1) ? NI_LSB_FIRST : NI_MSB_FIRST ;
00022 }
 | 
| 
 | ||||||||||||
| Swap arrays of 2 bytes (shorts). ----------------------------------------------------------------- Definition at line 33 of file niml_byteorder.c. References twobytes::a, twobytes::b, and tt. Referenced by NI_swap_column(). 
 | 
| 
 | ||||||||||||
| Swap arrays of 4 bytes (ints or floats). ----------------------------------------------------------------- Definition at line 54 of file niml_byteorder.c. References fourbytes::a, fourbytes::b, fourbytes::c, fourbytes::d, and tt. Referenced by NI_base64_to_val(), NI_binary_to_val(), and NI_swap_column(). 
 00055 {
00056    register int ii ;
00057    register fourbytes *tb = (fourbytes *) ar ;
00058    register unsigned char tt , uu ;
00059 
00060    for( ii=0 ; ii < n ; ii++ ){
00061       tt = tb[ii].a ; tb[ii].a = tb[ii].d ; tb[ii].d = tt ;
00062       uu = tb[ii].b ; tb[ii].b = tb[ii].c ; tb[ii].c = uu ;
00063    }
00064    return ;
00065 }
 | 
| 
 | ||||||||||||
| Swap arrays of 8 bytes (doubles or 64 bit ints). ----------------------------------------------------------------- Definition at line 76 of file niml_byteorder.c. References eightbytes::a, eightbytes::b, eightbytes::c, eightbytes::d, eightbytes::e, eightbytes::f, eightbytes::g, eightbytes::h, and tt. Referenced by NI_swap_column(). 
 00077 {
00078    register int ii ;
00079    register eightbytes *tb = (eightbytes *) ar ;
00080    register unsigned char tt , uu , vv , ww ;
00081 
00082    for( ii=0 ; ii < n ; ii++ ){
00083       tt = tb[ii].a ; tb[ii].a = tb[ii].h ; tb[ii].h = tt ;
00084       uu = tb[ii].b ; tb[ii].b = tb[ii].g ; tb[ii].g = uu ;
00085       vv = tb[ii].c ; tb[ii].c = tb[ii].f ; tb[ii].f = vv ;
00086       ww = tb[ii].d ; tb[ii].d = tb[ii].e ; tb[ii].e = ww ;
00087    }
00088    return ;
00089 }
 | 
 
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
 
 
 
 
       
	   
	   
	   
	  