Skip to content

Commit 4786651

Browse files
committed
Move endianness bits into its own header.
1 parent ee51c90 commit 4786651

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

kaitai/endian.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef KAITAI_ENDIAN_H
2+
#define KAITAI_ENDIAN_H
3+
4+
#if defined(__APPLE__)
5+
#include <machine/endian.h>
6+
#include <libkern/OSByteOrder.h>
7+
#define bswap_16(x) OSSwapInt16(x)
8+
#define bswap_32(x) OSSwapInt32(x)
9+
#define bswap_64(x) OSSwapInt64(x)
10+
#define __BIG_ENDIAN BIG_ENDIAN
11+
#define __LITTLE_ENDIAN LITTLE_ENDIAN
12+
#define __BYTE_ORDER BYTE_ORDER
13+
#elif defined(_MSC_VER) // !__APPLE__
14+
#include <stdlib.h>
15+
#define bswap_16(x) _byteswap_ushort(x)
16+
#define bswap_32(x) _byteswap_ulong(x)
17+
#define bswap_64(x) _byteswap_uint64(x)
18+
#define __BIG_ENDIAN 4321
19+
#define __LITTLE_ENDIAN 1234
20+
#define __BYTE_ORDER __LITTLE_ENDIAN
21+
#else // !__APPLE__ or !_MSC_VER
22+
#include <endian.h>
23+
#include <byteswap.h>
24+
#endif
25+
26+
#endif

kaitai/kistream.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
11
#include <kaitai/kistream.h>
2-
3-
#if defined(__APPLE__)
4-
#include <machine/endian.h>
5-
#include <libkern/OSByteOrder.h>
6-
#define bswap_16(x) OSSwapInt16(x)
7-
#define bswap_32(x) OSSwapInt32(x)
8-
#define bswap_64(x) OSSwapInt64(x)
9-
#define __BYTE_ORDER BYTE_ORDER
10-
#define __BIG_ENDIAN BIG_ENDIAN
11-
#define __LITTLE_ENDIAN LITTLE_ENDIAN
12-
#elif defined(_MSC_VER) // !__APPLE__
13-
#include <stdlib.h>
14-
#define __LITTLE_ENDIAN 1234
15-
#define __BIG_ENDIAN 4321
16-
#define __BYTE_ORDER __LITTLE_ENDIAN
17-
#define bswap_16(x) _byteswap_ushort(x)
18-
#define bswap_32(x) _byteswap_ulong(x)
19-
#define bswap_64(x) _byteswap_uint64(x)
20-
#else // !__APPLE__ or !_MSC_VER
21-
#include <endian.h>
22-
#include <byteswap.h>
23-
#endif
2+
#include <kaitai/endian.h>
243

254
#include <iostream>
265
#include <vector>

0 commit comments

Comments
 (0)