All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
target/Linux-x86_64/include/citrusleaf/cf_byte_order.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 #pragma once
23 
24 #if defined(__linux__)
25 
26 #include <netinet/in.h>
27 #include <asm/byteorder.h>
28 
29 #define cf_swap_to_be16(_n) __cpu_to_be16(_n)
30 #define cf_swap_from_be16(_n) __be16_to_cpu(_n)
31 
32 #define cf_swap_to_be32(_n) __cpu_to_be32(_n)
33 #define cf_swap_from_be32(_n) __be32_to_cpu(_n)
34 
35 #define cf_swap_to_be64(_n) __cpu_to_be64(_n)
36 #define cf_swap_from_be64(_n) __be64_to_cpu(_n)
37 
38 #endif // __linux__
39 
40 #if defined(__APPLE__)
41 #include <libkern/OSByteOrder.h>
42 #include <arpa/inet.h>
43 
44 #define cf_swap_to_be16(_n) OSSwapHostToBigInt16(_n)
45 #define cf_swap_from_be16(_n) OSSwapBigToHostInt16(_n)
46 
47 #define cf_swap_to_be32(_n) OSSwapHostToBigInt32(_n)
48 #define cf_swap_from_be32(_n) OSSwapBigToHostInt32(_n)
49 
50 #define cf_swap_to_be64(_n) OSSwapHostToBigInt64(_n)
51 #define cf_swap_from_be64(_n) OSSwapBigToHostInt64(_n)
52 
53 #endif // __APPLE__
54 
55 #if defined(CF_WINDOWS)
56 #include <stdint.h>
57 #include <stdlib.h>
58 #include <WinSock2.h>
59 
60 #define cf_swap_to_be16(_n) _byteswap_uint16(_n)
61 #define cf_swap_from_be16(_n) _byteswap_uint16(_n)
62 
63 #define cf_swap_to_be32(_n) _byteswap_uint32(_n)
64 #define cf_swap_from_be32(_n) _byteswap_uint32(_n)
65 
66 #define cf_swap_to_be64(_n) _byteswap_uint64(_n)
67 #define cf_swap_from_be64(_n) _byteswap_uint64(_n)
68 #endif // CF_WINDOWS