use a variant of <endian.h> on Mac OS

This commit is contained in:
Lephe 2019-06-28 13:44:03 -04:00
parent 5cdc20ed1f
commit 7efd917cf2
7 changed files with 71 additions and 5 deletions

View File

@ -1,6 +1,6 @@
#include <stdio.h>
#include <string.h>
#include <endian.h>
#include <endianness.h>
#include <fxg1a.h>
#include <g1a.h>

View File

@ -1,7 +1,7 @@
#include <fxg1a.h>
#include <stdio.h>
#include <string.h>
#include <endian.h>
#include <endianness.h>
/* sign(): Sign header by filling fixed fields and checksums */
void sign(struct g1a *g1a, size_t size)

33
fxg1a/endianness.h Normal file
View File

@ -0,0 +1,33 @@
//---
// Cross-platform endianness conversion. (seriously?)
//---
#ifndef FX_ENDIANNESS
#define FX_ENDIANNESS
#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define htobe16(x) OSSwapHostToBigInt16(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define be16toh(x) OSSwapBigToHostInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#elif defined(__linux__)
#include <sys/types.h>
#endif
#endif /* FX_ENDIANNESS */

View File

@ -1,5 +1,5 @@
#include <string.h>
#include <endian.h>
#include <endianness.h>
#include <fxg1a.h>
/*

33
fxos/endianness.h Normal file
View File

@ -0,0 +1,33 @@
//---
// Cross-platform endianness conversion. (seriously?)
//---
#ifndef FX_ENDIANNESS
#define FX_ENDIANNESS
#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define htobe16(x) OSSwapHostToBigInt16(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define be16toh(x) OSSwapBigToHostInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#elif defined(__linux__)
#include <sys/types.h>
#endif
#endif /* FX_ENDIANNESS */

View File

@ -3,7 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <endian.h>
#include <endianness.h>
char const *info_str =
"Header information:\n"

View File

@ -1,4 +1,4 @@
#include <endian.h>
#include <endianness.h>
#include <string.h>
#include <fxos.h>