Skip to content

Commit dfe2bb6

Browse files
committed
sparse.c: support macos
1 parent bb5a3dc commit dfe2bb6

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

sparse.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
*/
3131
#define _FILE_OFFSET_BITS 64
3232
#include <ctype.h>
33-
#include <endian.h>
3433
#include <errno.h>
3534
#include <inttypes.h>
3635
#include <stdbool.h>
@@ -39,6 +38,28 @@
3938
#include <string.h>
4039
#include <unistd.h>
4140

41+
#if defined(__APPLE__)
42+
#include <machine/endian.h>
43+
#include <libkern/OSByteOrder.h>
44+
45+
#define htobe16(x) OSSwapHostToBigInt16(x)
46+
#define htole16(x) OSSwapHostToLittleInt16(x)
47+
#define be16toh(x) OSSwapBigToHostInt16(x)
48+
#define le16toh(x) OSSwapLittleToHostInt16(x)
49+
50+
#define htobe32(x) OSSwapHostToBigInt32(x)
51+
#define htole32(x) OSSwapHostToLittleInt32(x)
52+
#define be32toh(x) OSSwapBigToHostInt32(x)
53+
#define le32toh(x) OSSwapLittleToHostInt32(x)
54+
55+
#define htobe64(x) OSSwapHostToBigInt64(x)
56+
#define htole64(x) OSSwapHostToLittleInt64(x)
57+
#define be64toh(x) OSSwapBigToHostInt64(x)
58+
#define le64toh(x) OSSwapLittleToHostInt64(x)
59+
#else
60+
#include <endian.h>
61+
#endif
62+
4263
#include "sparse.h"
4364

4465
int sparse_header_parse(int fd, sparse_header_t* sparse_header)

0 commit comments

Comments
 (0)