Merged revisions 10129-10142 via svnmerge from
[wvapps.git] / funfs / funfsbyteswap.h
blobd2faa9a204274a0e237b2a61f1f448b6104a7ed7
1 #ifndef __FunFSBYTESWAP_H
2 #define __FunFSBYTESWAP_H
4 #include <endian.h>
5 #include <byteswap.h>
6 #include <netinet/in.h>
8 #if __BYTE_ORDER == __LITTLE_ENDIAN
9 # define SWAP64(x) _swap64(x)
10 # define SWAP32(x) _swap32(x)
11 # define SWAP16(x) _swap16(x)
12 #elif __BYTE_ORDER == __BIG_ENDIAN
13 # define SWAP64(x) x
14 # define SWAP32(x) x
15 # define SWAP16(x) x
16 #endif
19 inline unsigned long long int *_swap64(void *i)
21 unsigned long long int *& p = (unsigned long long int *)i;
22 __bswap_64(*p);
23 return p;
26 inline unsigned long int *_swap32(void *i)
28 unsigned long int *& p = (unsigned long int *)i;
29 *p = htonl(*p);
30 return p;
33 inline unsigned short int *_swap16(void *i)
35 unsigned short int *& p = (unsigned short int *)i;
36 *p = htons(*p);
37 return p;
40 inline unsigned long long int abswap(unsigned long long int i)
42 __bswap_64(i);
43 return i;
46 inline unsigned long int abswap(unsigned long int i)
48 return htonl(i);
51 inline unsigned short int abswap(unsigned short int i)
53 return htons(i);
56 #endif