Skip to content

Commit 716cb2e

Browse files
committed
cmds: provide endian helpers when missing
Windows doesn't provide the endian header file, in this case define the byte order helpers. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 95d7201 commit 716cb2e

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

libnvme/src/nvme/cmds.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,36 @@
1010

1111
#pragma once
1212

13-
#include <endian.h>
1413
#include <errno.h>
1514
#include <string.h>
1615

16+
#ifdef __linux__
17+
#include <endian.h>
18+
#else
19+
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
20+
#define htobe16(x) (x)
21+
#define htobe32(x) (x)
22+
#define htobe64(x) (x)
23+
#define htole16(x) __builtin_bswap16(x)
24+
#define htole32(x) __builtin_bswap32(x)
25+
#define htole64(x) __builtin_bswap64(x)
26+
#define le16toh(x) __builtin_bswap16(x)
27+
#define le32toh(x) __builtin_bswap32(x)
28+
#define le64toh(x) __builtin_bswap64(x)
29+
#else
30+
/* Little-endian (most common case for Windows) */
31+
#define htobe16(x) __builtin_bswap16(x)
32+
#define htobe32(x) __builtin_bswap32(x)
33+
#define htobe64(x) __builtin_bswap64(x)
34+
#define htole16(x) (x)
35+
#define htole32(x) (x)
36+
#define htole64(x) (x)
37+
#define le16toh(x) (x)
38+
#define le32toh(x) (x)
39+
#define le64toh(x) (x)
40+
#endif
41+
#endif
42+
1743
#include <nvme/ioctl.h>
1844
#include <nvme/types.h>
1945

0 commit comments

Comments
 (0)