Make endianess detection more flexible

And fix it on FreeBSD, where _BIG_ENDIAN is not a flag indicating
big endian machine, but a constant to compare _BYTE_ORDER to.