diff --git a/lib/util.h b/lib/util.h index 308fd80..4052025 100644 --- a/lib/util.h +++ b/lib/util.h @@ -10,6 +10,17 @@ #define MAX(a,b) (((a)>(b))?(a):(b)) #define CLAMP(x, min, max) (MIN(MAX(x, min), max)) +#if defined(_WIN32) +// Windows has no htobe32, and is always virtually little-endiam +#define htobe32(x) htonl(x) +#define le16toh(x) (x) +#elif defined(__APPLE__) +// macOS has no htobe32 +#include +#define htobe32(x) OSSwapHostToBigInt32(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) +#endif // __APPLE__ + size_t read_line_from_fd(int fd, char *output, size_t max_output_size); size_t read_line_from_file(FILE *file, char *output, size_t max_output_size); size_t get_max_path_length(); @@ -26,4 +37,4 @@ uint16_t crc16(const void* data, size_t len); void print_hex(const void *data, size_t len); -#endif // VANILLA_UTIL_H \ No newline at end of file +#endif // VANILLA_UTIL_H