ED247 Library  VA2.3.0
Implementation of ED247-A standard
ed247_bswap.h
1 /* -*- mode: c++; c-basic-offset: 2 -*- */
2 //
3 // Define bswap_xx and htonx/ntohx functions.
4 //
5 #ifndef _ED247_BSWAP_H_
6 #define _ED247_BSWAP_H_
7 
8 
9 #ifdef __linux__
10 # define bswap_16(x) __builtin_bswap16(x)
11 # define bswap_32(x) __builtin_bswap32(x)
12 # define bswap_64(x) __builtin_bswap64(x)
13 #elif __QNXNTO__
14 # include <gulliver.h>
15 # define bswap_16(x) ENDIAN_RET16(x)
16 # define bswap_32(x) ENDIAN_RET32(x)
17 # define bswap_64(x) ENDIAN_RET64(x)
18 #elif _MSC_VER
19 # include <stdlib.h>
20 # include <winsock2.h>
21 # define bswap_16(x) _byteswap_ushort(x)
22 # define bswap_32(x) _byteswap_ulong(x)
23 # define bswap_64(x) _byteswap_uint64(x)
24 #elif _WIN32
25 # include <winsock2.h>
26 # define bswap_16(x) __builtin_bswap16(x)
27 # define bswap_32(x) __builtin_bswap32(x)
28 # define bswap_64(x) __builtin_bswap64(x)
29 #endif
30 
31 #ifdef htons
32 # undef htons
33 #endif
34 #define htons(x) bswap_16(x)
35 
36 #ifdef ntohs
37 # undef ntohs
38 #endif
39 #define ntohs(x) bswap_16(x)
40 
41 #ifdef ntohl
42 # undef ntohl
43 #endif
44 #define ntohl(x) bswap_32(x)
45 
46 #ifdef htonl
47 # undef htonl
48 #endif
49 #define htonl(x) bswap_32(x)
50 
51 #endif