Switchtec Userspace PROJECT_NUMBER = 4.0
Loading...
Searching...
No Matches
endian.h
1/*
2 * Microsemi Switchtec(tm) PCIe Management Library
3 * Copyright (c) 2017, Microsemi Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25#ifndef LIBSWITCHTEC_ENDIAN_H
26#define LIBSWITCHTEC_ENDIAN_H
27
28#include "portable.h"
29
30#if defined(__linux__)
31# include <endian.h>
32
33#elif defined(__WINDOWS__)
34# include <winsock2.h>
35# include <sys/param.h>
36
37# if BYTE_ORDER == LITTLE_ENDIAN
38
39# define htobe16(x) htons(x)
40# define htole16(x) (x)
41# define be16toh(x) ntohs(x)
42# define le16toh(x) (x)
43
44# define htobe32(x) htonl(x)
45# define htole32(x) (x)
46# define be32toh(x) ntohl(x)
47# define le32toh(x) (x)
48
49# define htobe64(x) htonll(x)
50# define htole64(x) (x)
51# define be64toh(x) ntohll(x)
52# define le64toh(x) (x)
53
54# elif BYTE_ORDER == BIG_ENDIAN
55
56# define htobe16(x) (x)
57# define htole16(x) __builtin_bswap16(x)
58# define be16toh(x) (x)
59# define le16toh(x) __builtin_bswap16(x)
60
61# define htobe32(x) (x)
62# define htole32(x) __builtin_bswap32(x)
63# define be32toh(x) (x)
64# define le32toh(x) __builtin_bswap32(x)
65
66# define htobe64(x) (x)
67# define htole64(x) __builtin_bswap64(x)
68# define be64toh(x) (x)
69# define le64toh(x) __builtin_bswap64(x)
70
71# endif
72#endif
73
74#endif