1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
| | /* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright Red Hat
* Author: David Gibson <david@gibson.dropbear.id.au>
*
* Definitions used by both passt/pasta and other tools
*/
#ifndef COMMON_H
#define COMMON_H
#define VERSION_BLOB \
VERSION "\n" \
"Copyright Red Hat\n" \
"GNU General Public License, version 2 or later\n" \
" <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n" \
"This is free software: you are free to change and redistribute it.\n" \
"There is NO WARRANTY, to the extent permitted by law.\n\n"
/* FPRINTF() intentionally silences cert-err33-c clang-tidy warnings */
#define FPRINTF(f, ...) (void)fprintf(f, __VA_ARGS__)
#define BIT(n) (1UL << (n))
#ifndef __bswap_constant_16
#define __bswap_constant_16(x) \
((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
#endif
#ifndef __bswap_constant_32
#define __bswap_constant_32(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#endif
#ifndef __bswap_constant_32
#define __bswap_constant_32(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#endif
#ifndef __bswap_constant_64
#define __bswap_constant_64(x) \
((((x) & 0xff00000000000000ULL) >> 56) | \
(((x) & 0x00ff000000000000ULL) >> 40) | \
(((x) & 0x0000ff0000000000ULL) >> 24) | \
(((x) & 0x000000ff00000000ULL) >> 8) | \
(((x) & 0x00000000ff000000ULL) << 8) | \
(((x) & 0x0000000000ff0000ULL) << 24) | \
(((x) & 0x000000000000ff00ULL) << 40) | \
(((x) & 0x00000000000000ffULL) << 56))
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
#define htons_constant(x) (x)
#define htonl_constant(x) (x)
#define htonll_constant(x) (x)
#define ntohs_constant(x) (x)
#define ntohl_constant(x) (x)
#define ntohll_constant(x) (x)
#else
#define htons_constant(x) (__bswap_constant_16(x))
#define htonl_constant(x) (__bswap_constant_32(x))
#define htonll_constant(x) (__bswap_constant_64(x))
#define ntohs_constant(x) (__bswap_constant_16(x))
#define ntohl_constant(x) (__bswap_constant_32(x))
#define ntohll_constant(x) (__bswap_constant_64(x))
#endif
#define ntohll(x) (be64toh((x)))
#define htonll(x) (htobe64((x)))
#endif /* _COMMON_H */
|