]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/py/src/ext/endian.h
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 #ifndef THRIFT_PY_ENDIAN_H
21 #define THRIFT_PY_ENDIAN_H
26 #include <netinet/in.h>
29 #pragma comment(lib, "ws2_32.lib")
30 #define BIG_ENDIAN (4321)
31 #define LITTLE_ENDIAN (1234)
32 #define BYTE_ORDER LITTLE_ENDIAN
33 #define inline __inline
36 /* Fix endianness issues on Solaris */
37 #if defined(__SVR4) && defined(__sun)
38 #if defined(__i386) && !defined(__i386__)
43 #define BIG_ENDIAN (4321)
46 #define LITTLE_ENDIAN (1234)
49 /* I386 is LE, even on Solaris */
50 #if !defined(BYTE_ORDER) && defined(__i386__)
51 #define BYTE_ORDER LITTLE_ENDIAN
56 #if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
57 #define __BYTE_ORDER BYTE_ORDER
58 #define __LITTLE_ENDIAN LITTLE_ENDIAN
59 #define __BIG_ENDIAN BIG_ENDIAN
61 #error "Cannot determine endianness"
65 // Same comment as the enum. Sorry.
66 #if __BYTE_ORDER == __BIG_ENDIAN
69 #if defined(__GNUC__) && defined(__GLIBC__)
71 #define letohll(n) bswap_64(n)
72 #define htolell(n) bswap_64(n)
73 #else /* GNUC & GLIBC */
74 #define letohll(n) ((((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32))
75 #define htolell(n) ((((unsigned long long)htonl(n)) << 32) + htonl(n >> 32))
77 #elif __BYTE_ORDER == __LITTLE_ENDIAN
78 #if defined(__GNUC__) && defined(__GLIBC__)
80 #define ntohll(n) bswap_64(n)
81 #define htonll(n) bswap_64(n)
82 #elif defined(_MSC_VER)
84 #define ntohll(n) _byteswap_uint64(n)
85 #define htonll(n) _byteswap_uint64(n)
86 #else /* GNUC & GLIBC */
87 #define ntohll(n) ((((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32))
88 #define htonll(n) ((((unsigned long long)htonl(n)) << 32) + htonl(n >> 32))
89 #endif /* GNUC & GLIBC */
90 #define letohll(n) (n)
91 #define htolell(n) (n)
92 #else /* __BYTE_ORDER */
93 #error "Can't define htonll or ntohll!"
96 #endif // THRIFT_PY_ENDIAN_H