]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - SQUASHFS/squashfs-tools-4.4/squashfs-tools/swap.c
2 * Copyright (c) 2009, 2010
3 * Phillip Lougher <phillip@squashfs.org.uk>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2,
8 * or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #define __BYTE_ORDER BYTE_ORDER
24 #define __BIG_ENDIAN BIG_ENDIAN
25 #define __LITTLE_ENDIAN LITTLE_ENDIAN
30 #if __BYTE_ORDER == __BIG_ENDIAN
31 void swap_le16(void *src
, void *dest
)
33 unsigned char *s
= src
;
34 unsigned char *d
= dest
;
41 void swap_le32(void *src
, void *dest
)
43 unsigned char *s
= src
;
44 unsigned char *d
= dest
;
53 void swap_le64(void *src
, void *dest
)
55 unsigned char *s
= src
;
56 unsigned char *d
= dest
;
69 unsigned short inswap_le16(unsigned short num
)
76 unsigned int inswap_le32(unsigned int num
)
79 ((num
& 0xff0000) >> 8) |
80 ((num
& 0xff00) << 8) |
85 long long inswap_le64(long long n
)
87 unsigned long long num
= n
;
90 ((num
& 0xff000000000000LL
) >> 40) |
91 ((num
& 0xff0000000000LL
) >> 24) |
92 ((num
& 0xff00000000LL
) >> 8) |
93 ((num
& 0xff000000) << 8) |
94 ((num
& 0xff0000) << 24) |
95 ((num
& 0xff00) << 40) |
100 #define SWAP_LE_NUM(BITS) \
101 void swap_le##BITS##_num(void *s, void *d, int n) \
104 for(i = 0; i < n; i++, s += BITS / 8, d += BITS / 8)\
105 swap_le##BITS(s, d);\
112 #define INSWAP_LE_NUM(BITS, TYPE) \
113 void inswap_le##BITS##_num(TYPE *s, int n) \
116 for(i = 0; i < n; i++)\
117 s[i] = inswap_le##BITS(s[i]);\
120 INSWAP_LE_NUM(16, unsigned short)
121 INSWAP_LE_NUM(32, unsigned int)
122 INSWAP_LE_NUM(64, long long)