2 ** Copyright (C) 1999-2003 Erik de Castro Lopo <erikd@zip.com.au>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU Lesser General Public License for more details.
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 /*-----------------------------------------------------------------------------------------------
22 ** Generic functions for performing endian swapping on integer arrays.
26 endswap_short_array (short *ptr
, int len
)
30 unsigned char *ucptr
, temp
;
32 ucptr
= ((unsigned char *) ptr
) + 2 * len
;
37 ucptr
[0] = ucptr
[1] ;
45 ptr
[len
] = ENDSWAP_SHORT (temp
) ;
48 } /* endswap_short_array */
51 endswap_int_array (int *ptr
, int len
)
54 unsigned char *ucptr
, temp
;
56 ucptr
= ((unsigned char *) ptr
) + 4 * len
;
62 ucptr
[0] = ucptr
[3] ;
66 ucptr
[1] = ucptr
[2] ;
75 ptr
[len
] = ENDSWAP_INT (temp
) ;
78 } /* endswap_int_array */
80 /* This function assumes that sizeof (long) == 8, but works correctly even
81 ** is sizeof (long) == 4.
84 endswap_long_array (long *ptr
, int len
)
85 { unsigned char *ucptr
, temp
;
87 ucptr
= (unsigned char *) ptr
+ 8 * len
;
93 ucptr
[0] = ucptr
[7] ;
97 ucptr
[1] = ucptr
[6] ;
101 ucptr
[2] = ucptr
[5] ;
105 ucptr
[3] = ucptr
[4] ;
108 } /* endswap_long_array */
110 /*========================================================================================
114 endswap_short_copy (short *dest
, short *src
, int len
)
119 psrc
= ((char *) src
) + 2 * len
;
120 pdest
= ((char *) dest
) + 2 * len
;
126 pdest
[0] = psrc
[1] ;
127 pdest
[1] = psrc
[0] ;
132 dest
[len
] = ENDSWAP_SHORT (src
[len
]) ;
135 } /* endswap_short_copy */
138 endswap_int_copy (int *dest
, int *src
, int len
)
143 psrc
= ((char *) src
) + 4 * len
;
144 pdest
= ((char *) dest
) + 4 * len
;
150 pdest
[0] = psrc
[3] ;
151 pdest
[1] = psrc
[2] ;
152 pdest
[2] = psrc
[1] ;
153 pdest
[3] = psrc
[0] ;
158 dest
[len
] = ENDSWAP_INT (src
[len
]) ;
161 } /* endswap_int_copy */
163 /* This function assumes that sizeof (long) == 8, but works correctly even
164 ** is sizeof (long) == 4.
167 endswap_long_copy (long *dest
, long *src
, int len
)
168 { char *psrc
, *pdest
;
170 psrc
= (char *) src
+ 8 * len
;
171 pdest
= (char *) dest
+ 8 * len
;
177 pdest
[0] = psrc
[7] ;
178 pdest
[1] = psrc
[6] ;
179 pdest
[2] = psrc
[5] ;
180 pdest
[3] = psrc
[4] ;
181 pdest
[4] = psrc
[3] ;
182 pdest
[5] = psrc
[2] ;
183 pdest
[6] = psrc
[1] ;
184 pdest
[7] = psrc
[0] ;
186 } /* endswap_long_copy */