/* 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__

/* Undefine first to avoid conflicts */
#  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 htobe16
#    undef htobe16
#  endif
#  ifdef htobe32
#    undef htobe32
#  endif
#  ifdef htobe64
#    undef htobe64
#  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)
#    define be32toh(x) ENDIAN_RET32(x)
#    define be64toh(x) ENDIAN_RET64(x)
#    define htobe16(x) ENDIAN_RET16(x)   /* needed for ne2000 */
#    define htobe32(x) ENDIAN_RET32(x)
#    define htobe64(x) ENDIAN_RET64(x)
#  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)
#    define be32toh(x) (x)
#    define be64toh(x) (x)
#    define htobe16(x) (x)
#    define htobe32(x) (x)
#    define htobe64(x) (x)
#  endif

#endif /* __QNXNTO__ */

#endif /* DOSBOX_QNX_ENDIAN_H */
