stbrumme / hash-library

Portable C++ hashing library

Home Page:https://create.stephan-brumme.com/hash-library/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OSX has no endian.h

NiklasRosenstein opened this issue · comments

It seems OSX has no endian.h, but it also looks like it is not needed.

Possible solution to make sha256.cpp compile on OSX:

Replace

hash-library/sha256.cpp

Lines 9 to 12 in a8a88f8

// big endian architectures need #define __BYTE_ORDER __BIG_ENDIAN
#ifndef _MSC_VER
#include <endian.h>
#endif

with

#if !defined(_MSC_VER) && !defined(__APPLE__)
#include <endian.h>
#endif

The "default" byte order is little endian (and your system is little endian, too).
If the __BYTE_ORDER macro isnt defined then little endian is assumed - and thats the case if you skip #include <endian.h>

This preprocesser statement in line 98 "detects" big endian:
#if defined(__BYTE_ORDER) && (__BYTE_ORDER != 0) && (__BYTE_ORDER == __BIG_ENDIAN)

Big endian systems are rare nowadays.

I made this change to be able to compile on mac:

2018-12-09_13h03_35

Just removing the include might work for Macs but breaks the whole thing on big-endian Unix machines.
A better workaround is to wrap the include by another #ifndef __APPLE__

#include <machine/endian.h> worked on Mac. Will that work on Unix?

To have support for both OSX and Linux/WIndows, you can use

#include <sys/types.h>