| ... | @@ -10,6 +10,28 @@ | ... | @@ -10,6 +10,28 @@ |
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | #include <math.h> | 11 | #include <math.h> |
| 12 | | 12 | |
| | 13 | // Every OSes seem to define endianness macros in different files. |
| | 14 | #if defined(__APPLE__) |
| | 15 | #include <machine/endian.h> |
| | 16 | #define ZIG_BIG_ENDIAN BIG_ENDIAN |
| | 17 | #define ZIG_LITTLE_ENDIAN LITTLE_ENDIAN |
| | 18 | #define ZIG_BYTE_ORDER BYTE_ORDER |
| | 19 | #elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) |
| | 20 | #include <sys/endian.h> |
| | 21 | #define ZIG_BIG_ENDIAN _BIG_ENDIAN |
| | 22 | #define ZIG_LITTLE_ENDIAN _LITTLE_ENDIAN |
| | 23 | #define ZIG_BYTE_ORDER _BYTE_ORDER |
| | 24 | #elif defined(_WIN32) || defined(_WIN64) |
| | 25 | // Assume that Windows installations are always little endian. |
| | 26 | #define ZIG_LITTLE_ENDIAN 1 |
| | 27 | #define ZIG_BYTE_ORDER ZIG_LITTLE_ENDIAN |
| | 28 | #else // Linux |
| | 29 | #include <endian.h> |
| | 30 | #define ZIG_BIG_ENDIAN __BIG_ENDIAN |
| | 31 | #define ZIG_LITTLE_ENDIAN __LITTLE_ENDIAN |
| | 32 | #define ZIG_BYTE_ORDER __BYTE_ORDER |
| | 33 | #endif |
| | 34 | |
| 13 | #define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf)) | 35 | #define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf)) |
| 14 | #define shlim(f, lim) __shlim((f), (lim)) | 36 | #define shlim(f, lim) __shlim((f), (lim)) |
| 15 | #define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f)) | 37 | #define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f)) |
| ... | @@ -47,8 +69,7 @@ | ... | @@ -47,8 +69,7 @@ |
| 47 | | 69 | |
| 48 | #define DECIMAL_DIG 36 | 70 | #define DECIMAL_DIG 36 |
| 49 | | 71 | |
| 50 | | 72 | #if defined(ZIG_BYTE_ORDER) && ZIG_BYTE_ORDER == ZIG_LITTLE_ENDIAN |
| 51 | #if __BYTE_ORDER == __LITTLE_ENDIAN | | |
| 52 | union ldshape { | 73 | union ldshape { |
| 53 | float128_t f; | 74 | float128_t f; |
| 54 | struct { | 75 | struct { |
| ... | @@ -62,7 +83,7 @@ union ldshape { | ... | @@ -62,7 +83,7 @@ union ldshape { |
| 62 | uint64_t hi; | 83 | uint64_t hi; |
| 63 | } i2; | 84 | } i2; |
| 64 | }; | 85 | }; |
| 65 | #elif __BYTE_ORDER == __BIG_ENDIAN | 86 | #elif defined(ZIG_BYTE_ORDER) && ZIG_BYTE_ORDER == ZIG_BIG_ENDIAN |
| 66 | union ldshape { | 87 | union ldshape { |
| 67 | float128_t f; | 88 | float128_t f; |
| 68 | struct { | 89 | struct { |
| ... | @@ -76,6 +97,7 @@ union ldshape { | ... | @@ -76,6 +97,7 @@ union ldshape { |
| 76 | uint64_t lo; | 97 | uint64_t lo; |
| 77 | } i2; | 98 | } i2; |
| 78 | }; | 99 | }; |
| | 100 | #else |
| 79 | #error Unsupported endian | 101 | #error Unsupported endian |
| 80 | #endif | 102 | #endif |
| 81 | | 103 | |