/* QNX aarch64 endian compatibility header - defensive version */
#ifndef DOSBOX_QNX_ENDIAN_H
#define DOSBOX_QNX_ENDIAN_H

#include <stdint.h>
#include <gulliver.h>

#ifdef __QNXNTO__

/* First, undefine anything that might conflict with net/netbyte.h */
#  ifdef be16toh
#    undef be16toh
#  endif
#  ifdef be32toh
#    undef be32toh
#  endif
#  ifdef be64toh
#    undef be64toh
#  endif
#  ifdef le16toh
#    undef le16toh
#  endif
#  ifdef le32toh
#    undef le32toh
#  endif
#  ifdef le64toh
#    undef le64toh
#  endif
#  ifdef htole16
#    undef htole16
#  endif
#  ifdef htole32
#    undef htole32
#  endif
#  ifdef htole64
#    undef htole64
#  endif

#  if defined(__LITTLEENDIAN__)
#    define le16toh(x) (x)
#    define le32toh(x) (x)
#    define le64toh(x) (x)
#    define htole16(x) (x)
#    define htole32(x) (x)
#    define htole64(x) (x)
#    define be16toh(x) ENDIAN_RET16(x)   /* only this one is needed for ISO/Joliet */
#  else
#    define le16toh(x) ENDIAN_RET16(x)
#    define le32toh(x) ENDIAN_RET32(x)
#    define le64toh(x) ENDIAN_RET64(x)
#    define htole16(x) (x)
#    define htole32(x) (x)
#    define htole64(x) (x)
#    define be16toh(x) (x)
#  endif

#endif /* __QNXNTO__ */

#endif /* DOSBOX_QNX_ENDIAN_H */
