Browse Source

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

dev
Lephe 4 months ago
parent
commit
7efd917cf2
7 changed files with 71 additions and 5 deletions
  1. 1
    1
      fxg1a/dump.c
  2. 1
    1
      fxg1a/edit.c
  3. 33
    0
      fxg1a/endianness.h
  4. 1
    1
      fxg1a/util.c
  5. 33
    0
      fxos/endianness.h
  6. 1
    1
      fxos/info.c
  7. 1
    1
      fxos/os.c

+ 1
- 1
fxg1a/dump.c View File

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

#include <fxg1a.h>
#include <g1a.h>

+ 1
- 1
fxg1a/edit.c 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
- 0
fxg1a/endianness.h 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 */

+ 1
- 1
fxg1a/util.c View File

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

/*

+ 33
- 0
fxos/endianness.h 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 */

+ 1
- 1
fxos/info.c 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"

+ 1
- 1
fxos/os.c View File

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

#include <fxos.h>

Loading…
Cancel
Save