Fix endian detection on non-linux systems

f975f736408f32e7384cf38270a7806e68d5e112 introduced inclusion of endian.h, which is not a standard header. Move the code of this commit into a __linux__ condition to fix this problem.