include: implement REUSE with SPDX identifiers
[lttng-ust.git] / include / lttng / ust-endian.h
CommitLineData
1c196845
MJ
1// SPDX-FileCopyrightText: 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2//
3// SPDX-License-Identifier: MIT
06e646e0
MJ
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:
2ae57758 21 *
06e646e0
MJ
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 *)
2ae57758
MD
25 */
26
c0c0989a
MJ
27#ifndef _LTTNG_UST_ENDIAN_H
28#define _LTTNG_UST_ENDIAN_H
29
2928fe5a 30#if (defined(__linux__) || defined(__CYGWIN__))
2ae57758 31#include <endian.h>
3208818b 32#include <byteswap.h>
2ae57758 33
baa8acf3
MJ
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)
484fc193 37
baa8acf3
MJ
38#define LTTNG_UST_BYTE_ORDER __BYTE_ORDER
39#define LTTNG_UST_LITTLE_ENDIAN __LITTLE_ENDIAN
40#define LTTNG_UST_BIG_ENDIAN __BIG_ENDIAN
484fc193 41
ad496c21 42#ifdef __FLOAT_WORD_ORDER
baa8acf3 43#define LTTNG_UST_FLOAT_WORD_ORDER __FLOAT_WORD_ORDER
ad496c21 44#else /* __FLOAT_WORD_ORDER */
baa8acf3 45#define LTTNG_UST_FLOAT_WORD_ORDER __BYTE_ORDER
ad496c21 46#endif /* __FLOAT_WORD_ORDER */
baa8acf3
MJ
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
c5a5ae4f 59#define LTTNG_UST_FLOAT_WORD_ORDER BYTE_ORDER
baa8acf3
MJ
60
61#else
62#error "Please add support for your OS."
63#endif
ad496c21 64
2ae57758 65#endif /* _LTTNG_UST_ENDIAN_H */
This page took 0.036913 seconds and 4 git commands to generate.