include: implement REUSE with SPDX identifiers
[lttng-ust.git] / include / lttng / ust-endian.h
... / ...
CommitLineData
1// SPDX-FileCopyrightText: 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2//
3// SPDX-License-Identifier: MIT
4
5/*
6 * This header defines the following endian macros based on the current
7 * platform endian headers:
8 *
9 * BYTE_ORDER this macro shall have a value equal to one
10 * of the *_ENDIAN macros in this header.
11 * FLOAT_WORD_ORDER this macro shall have a value equal to one
12 * of the *_ENDIAN macros in this header.
13 * LITTLE_ENDIAN if BYTE_ORDER == LITTLE_ENDIAN, the host
14 * byte order is from least significant to
15 * most significant.
16 * BIG_ENDIAN if BYTE_ORDER == BIG_ENDIAN, the host byte
17 * order is from most significant to least
18 * significant.
19 *
20 * Direct byte swapping interfaces:
21 *
22 * uint16_t bswap_16(uint16_t x); (* swap bytes 16-bit word *)
23 * uint32_t bswap_32(uint32_t x); (* swap bytes 32-bit word *)
24 * uint64_t bswap_64(uint32_t x); (* swap bytes 64-bit word *)
25 */
26
27#ifndef _LTTNG_UST_ENDIAN_H
28#define _LTTNG_UST_ENDIAN_H
29
30#if (defined(__linux__) || defined(__CYGWIN__))
31#include <endian.h>
32#include <byteswap.h>
33
34#define lttng_ust_bswap_16(x) bswap_16(x)
35#define lttng_ust_bswap_32(x) bswap_32(x)
36#define lttng_ust_bswap_64(x) bswap_64(x)
37
38#define LTTNG_UST_BYTE_ORDER __BYTE_ORDER
39#define LTTNG_UST_LITTLE_ENDIAN __LITTLE_ENDIAN
40#define LTTNG_UST_BIG_ENDIAN __BIG_ENDIAN
41
42#ifdef __FLOAT_WORD_ORDER
43#define LTTNG_UST_FLOAT_WORD_ORDER __FLOAT_WORD_ORDER
44#else /* __FLOAT_WORD_ORDER */
45#define LTTNG_UST_FLOAT_WORD_ORDER __BYTE_ORDER
46#endif /* __FLOAT_WORD_ORDER */
47
48#elif defined(__FreeBSD__)
49
50#include <sys/endian.h>
51
52#define lttng_ust_bswap_16(x) bswap16(x)
53#define lttng_ust_bswap_32(x) bswap32(x)
54#define lttng_ust_bswap_64(x) bswap64(x)
55
56#define LTTNG_UST_BYTE_ORDER BYTE_ORDER
57#define LTTNG_UST_LITTLE_ENDIAN LITTLE_ENDIAN
58#define LTTNG_UST_BIG_ENDIAN BIG_ENDIAN
59#define LTTNG_UST_FLOAT_WORD_ORDER BYTE_ORDER
60
61#else
62#error "Please add support for your OS."
63#endif
64
65#endif /* _LTTNG_UST_ENDIAN_H */
This page took 0.022133 seconds and 4 git commands to generate.