Show the file size of the files in the tmp_dir on the LCD.
[ruwai.git] / software / c++ / ruwaicom / src / libmseed / gswap.c
blobddccfbc500d332b99e2708456486986320c93705
1 /***************************************************************************
2 * gswap.c:
4 * Functions for generalized, in-place byte swapping between LSBF and
5 * MSBF byte orders.
7 * Some standard integer types are needed, namely uint8_t and
8 * uint32_t, (these are normally declared by including inttypes.h or
9 * stdint.h). Each function expects it's input to be a void pointer
10 * to a quantity of the appropriate size.
12 * There are two versions of most routines, one that works on
13 * quantities regardless of alignment (gswapX) and one that works on
14 * memory aligned quantities (gswapXa). The memory aligned versions
15 * (gswapXa) are much faster than the other versions (gswapX), but the
16 * memory *must* be aligned.
18 * Written by Chad Trabant,
19 * IRIS Data Management Center
21 * Version: 2010.006
22 ***************************************************************************/
24 #include "lmplatform.h"
26 /* Swap routines that work on any (aligned or not) quantities */
28 void
29 ms_gswap2 ( void *data2 )
31 uint8_t temp;
33 union
35 uint8_t c[2];
36 } dat;
38 memcpy( &dat, data2, 2 );
39 temp = dat.c[0];
40 dat.c[0] = dat.c[1];
41 dat.c[1] = temp;
42 memcpy( data2, &dat, 2 );
46 void
47 ms_gswap3 ( void *data3 )
49 uint8_t temp;
51 union
53 uint8_t c[3];
54 } dat;
56 memcpy( &dat, data3, 3 );
57 temp = dat.c[0];
58 dat.c[0] = dat.c[2];
59 dat.c[2] = temp;
60 memcpy( data3, &dat, 3 );
64 void
65 ms_gswap4 ( void *data4 )
67 uint8_t temp;
69 union {
70 uint8_t c[4];
71 } dat;
73 memcpy( &dat, data4, 4 );
74 temp = dat.c[0];
75 dat.c[0] = dat.c[3];
76 dat.c[3] = temp;
77 temp = dat.c[1];
78 dat.c[1] = dat.c[2];
79 dat.c[2] = temp;
80 memcpy( data4, &dat, 4 );
84 void
85 ms_gswap8 ( void *data8 )
87 uint8_t temp;
89 union
91 uint8_t c[8];
92 } dat;
94 memcpy( &dat, data8, 8 );
95 temp = dat.c[0];
96 dat.c[0] = dat.c[7];
97 dat.c[7] = temp;
99 temp = dat.c[1];
100 dat.c[1] = dat.c[6];
101 dat.c[6] = temp;
103 temp = dat.c[2];
104 dat.c[2] = dat.c[5];
105 dat.c[5] = temp;
107 temp = dat.c[3];
108 dat.c[3] = dat.c[4];
109 dat.c[4] = temp;
110 memcpy( data8, &dat, 8 );
113 /* Swap routines that work on memory aligned quantities */
115 void
116 ms_gswap2a ( void *data2 )
118 uint16_t *data = data2;
120 *data=(((*data>>8)&0xff) | ((*data&0xff)<<8));
124 void
125 ms_gswap4a ( void *data4 )
127 uint32_t *data = data4;
129 *data=(((*data>>24)&0xff) | ((*data&0xff)<<24) |
130 ((*data>>8)&0xff00) | ((*data&0xff00)<<8));
134 void
135 ms_gswap8a ( void *data8 )
137 uint32_t *data4 = data8;
138 uint32_t h0, h1;
140 h0 = data4[0];
141 h0 = (((h0>>24)&0xff) | ((h0&0xff)<<24) |
142 ((h0>>8)&0xff00) | ((h0&0xff00)<<8));
144 h1 = data4[1];
145 h1 = (((h1>>24)&0xff) | ((h1&0xff)<<24) |
146 ((h1>>8)&0xff00) | ((h1&0xff00)<<8));
148 data4[0] = h1;
149 data4[1] = h0;