1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source.  A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12/*
13 * Copyright 2016 Joyent, Inc.
14 */
15
16#ifndef _ENDIAN_H
17#define	_ENDIAN_H
18
19/*
20 * Endian conversion routines, see endian(3C)
21 */
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <sys/isa_defs.h>
28#include <inttypes.h>
29
30#define	__LITTLE_ENDIAN	1234
31#define	__BIG_ENDIAN	4321
32#define	__PDP_ENDIAN	3412
33
34#if	defined(_LITTLE_ENDIAN)
35#define	__BYTE_ORDER	LITTLE_ENDIAN
36#elif	defined(_BIG_ENDIAN)
37#define	__BYTE_ORDER	BIG_ENDIAN
38#else
39#error	"Unknown byte order"
40#endif	/* _LITTLE_ENDIAN */
41
42#define	LITTLE_ENDIAN	__LITTLE_ENDIAN
43#define	BIG_ENDIAN	__BIG_ENDIAN
44#define	BYTE_ORDER	__BYTE_ORDER
45
46extern uint16_t htobe16(uint16_t);
47extern uint32_t htobe32(uint32_t);
48extern uint64_t htobe64(uint64_t);
49
50extern uint16_t htole16(uint16_t);
51extern uint32_t htole32(uint32_t);
52extern uint64_t htole64(uint64_t);
53
54/* Supply both the old and new BSD names */
55extern uint16_t betoh16(uint16_t);
56extern uint16_t letoh16(uint16_t);
57extern uint16_t be16toh(uint16_t);
58extern uint16_t le16toh(uint16_t);
59
60extern uint32_t betoh32(uint32_t);
61extern uint32_t letoh32(uint32_t);
62extern uint32_t be32toh(uint32_t);
63extern uint32_t le32toh(uint32_t);
64
65extern uint64_t betoh64(uint64_t);
66extern uint64_t letoh64(uint64_t);
67extern uint64_t be64toh(uint64_t);
68extern uint64_t le64toh(uint64_t);
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* _ENDIAN_H */
75