2  * Public domain, stripped down version of:
 
   3  * https://gist.github.com/panzi/6856583
 
   6 #ifndef __PORTABLE_ENDIAN_H
 
   7 #define __PORTABLE_ENDIAN_H
 
   9 #if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
 
  15 #if defined(__linux__) || defined(__CYGWIN__)
 
  19 #elif defined(__APPLE__)
 
  21 #       include <libkern/OSByteOrder.h>
 
  23 #       define htole32(x) OSSwapHostToLittleInt32(x)
 
  24 #       define le32toh(x) OSSwapLittleToHostInt32(x)
 
  26 #elif defined(__OpenBSD__)
 
  28 #       include <sys/endian.h>
 
  30 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
 
  32 #       include <sys/endian.h>
 
  34 #       define le32toh(x) letoh32(x)
 
  36 #elif defined(__WINDOWS__)
 
  38 #       include <winsock2.h>
 
  39 #       include <sys/param.h>
 
  41 #       if BYTE_ORDER == LITTLE_ENDIAN
 
  43 #               define htole32(x) (x)
 
  44 #               define le32toh(x) (x)
 
  46 #       elif BYTE_ORDER == BIG_ENDIAN
 
  48                 /* that would be xbox 360 */
 
  50 #               define htole32(x) __builtin_bswap32(x)
 
  51 #               define le32toh(x) __builtin_bswap32(x)
 
  55 #               error byte order not supported
 
  61 #error platform not supported
 
  65 #endif /* __PORTABLE_ENDIAN_H */