|
| 1 | +/* |
| 2 | + * endian.h - Cross-platform endian compatibility header |
| 3 | + * |
| 4 | + * This file provides endian.h compatibility for platforms that don't have it |
| 5 | + * (like Windows and macOS). It gets included by fastpbkdf2.c when __GNUC__ is defined. |
| 6 | + */ |
| 7 | + |
| 8 | +#ifndef FASTPBKDF2_ENDIAN_H |
| 9 | +#define FASTPBKDF2_ENDIAN_H |
| 10 | + |
| 11 | +#ifdef __APPLE__ |
| 12 | + /* macOS approach: use system headers to define endian macros */ |
| 13 | + #include <machine/endian.h> |
| 14 | + #include <libkern/OSByteOrder.h> |
| 15 | + |
| 16 | + /* Define the Linux-style endian macros that fastpbkdf2.c expects */ |
| 17 | + #ifndef __BYTE_ORDER |
| 18 | + #define __BYTE_ORDER BYTE_ORDER |
| 19 | + #endif |
| 20 | + #ifndef __LITTLE_ENDIAN |
| 21 | + #define __LITTLE_ENDIAN LITTLE_ENDIAN |
| 22 | + #endif |
| 23 | + #ifndef __BIG_ENDIAN |
| 24 | + #define __BIG_ENDIAN BIG_ENDIAN |
| 25 | + #endif |
| 26 | + |
| 27 | +#elif defined(_WIN32) |
| 28 | + /* Windows doesn't have endian.h, but it's always little-endian on x86/x64 */ |
| 29 | + #ifndef __BYTE_ORDER |
| 30 | + #define __BYTE_ORDER 1234 |
| 31 | + #endif |
| 32 | + #ifndef __LITTLE_ENDIAN |
| 33 | + #define __LITTLE_ENDIAN 1234 |
| 34 | + #endif |
| 35 | + #ifndef __BIG_ENDIAN |
| 36 | + #define __BIG_ENDIAN 4321 |
| 37 | + #endif |
| 38 | + |
| 39 | +#else |
| 40 | + /* Linux and other Unix systems - include the real system endian.h */ |
| 41 | + #if __has_include(<endian.h>) |
| 42 | + #include_next <endian.h> |
| 43 | + #elif __has_include(<sys/endian.h>) |
| 44 | + #include <sys/endian.h> |
| 45 | + #else |
| 46 | + /* Fallback definitions for systems without endian headers */ |
| 47 | + #ifndef __BYTE_ORDER |
| 48 | + #ifdef __BYTE_ORDER__ |
| 49 | + #define __BYTE_ORDER __BYTE_ORDER__ |
| 50 | + #else |
| 51 | + #define __BYTE_ORDER 1234 /* Assume little-endian */ |
| 52 | + #endif |
| 53 | + #endif |
| 54 | + #ifndef __LITTLE_ENDIAN |
| 55 | + #ifdef __ORDER_LITTLE_ENDIAN__ |
| 56 | + #define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ |
| 57 | + #else |
| 58 | + #define __LITTLE_ENDIAN 1234 |
| 59 | + #endif |
| 60 | + #endif |
| 61 | + #ifndef __BIG_ENDIAN |
| 62 | + #ifdef __ORDER_BIG_ENDIAN__ |
| 63 | + #define __BIG_ENDIAN __ORDER_BIG_ENDIAN__ |
| 64 | + #else |
| 65 | + #define __BIG_ENDIAN 4321 |
| 66 | + #endif |
| 67 | + #endif |
| 68 | + #endif |
| 69 | +#endif |
| 70 | + |
| 71 | +#endif /* FASTPBKDF2_ENDIAN_H */ |
0 commit comments