eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

endian.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Compatibility shim for <endian.h>
  2. *
  3. * "License": Public Domain
  4. * "Original": https://gist.github.com/panzi/6856583
  5. *
  6. * I, Mathias Panzenböck, place this file hereby into the public domain. Use it
  7. * at your own risk for whatever you like. In case there are jurisdictions that
  8. * don't support putting things in the public domain you can also consider it
  9. * to be "dual licensed" under the BSD, MIT and Apache licenses, if you want
  10. * to. This code is trivial anyway. Consider it an example on how to get the
  11. * endian conversion functions on different platforms.
  12. *
  13. * Modifications also in the Public Domain and dual licensed under BSD, MIT and
  14. * Apache licenses (using the terms outlined above):
  15. *
  16. * Copyright (C) 2016 Reece H. Dunn
  17. */
  18. #ifndef ENDIAN_H_COMPAT_SHIM
  19. #define ENDIAN_H_COMPAT_SHIM
  20. #if defined(HAVE_ENDIAN_H)
  21. # pragma GCC system_header // Silence "warning: #include_next is a GCC extension"
  22. # include_next <endian.h>
  23. #elif defined(HAVE_SYS_ENDIAN_H)
  24. # include <sys/endian.h>
  25. # if !defined(be16toh)
  26. # define be16toh(x) betoh16(x)
  27. # endif
  28. # if !defined(le16toh)
  29. # define le16toh(x) letoh16(x)
  30. # endif
  31. # if !defined(be32toh)
  32. # define be32toh(x) betoh32(x)
  33. # endif
  34. # if !defined(le32toh)
  35. # define le32toh(x) letoh32(x)
  36. # endif
  37. # if !defined(be64toh)
  38. # define be64toh(x) betoh64(x)
  39. # endif
  40. # if !defined(le64toh)
  41. # define le64toh(x) letoh64(x)
  42. # endif
  43. #elif defined(__APPLE__)
  44. # include <libkern/OSByteOrder.h>
  45. # define htobe16(x) OSSwapHostToBigInt16(x)
  46. # define htole16(x) OSSwapHostToLittleInt16(x)
  47. # define be16toh(x) OSSwapBigToHostInt16(x)
  48. # define le16toh(x) OSSwapLittleToHostInt16(x)
  49. # define htobe32(x) OSSwapHostToBigInt32(x)
  50. # define htole32(x) OSSwapHostToLittleInt32(x)
  51. # define be32toh(x) OSSwapBigToHostInt32(x)
  52. # define le32toh(x) OSSwapLittleToHostInt32(x)
  53. # define htobe64(x) OSSwapHostToBigInt64(x)
  54. # define htole64(x) OSSwapHostToLittleInt64(x)
  55. # define be64toh(x) OSSwapBigToHostInt64(x)
  56. # define le64toh(x) OSSwapLittleToHostInt64(x)
  57. # define __BYTE_ORDER BYTE_ORDER
  58. # define __BIG_ENDIAN BIG_ENDIAN
  59. # define __LITTLE_ENDIAN LITTLE_ENDIAN
  60. # define __PDP_ENDIAN PDP_ENDIAN
  61. #elif defined(_WIN16) || defined(_WIN32) || defined(_WIN64)
  62. # if BYTE_ORDER == LITTLE_ENDIAN
  63. # include <winsock2.h>
  64. # define htobe16(x) htons(x)
  65. # define htole16(x) (x)
  66. # define be16toh(x) ntohs(x)
  67. # define le16toh(x) (x)
  68. # define htobe32(x) htonl(x)
  69. # define htole32(x) (x)
  70. # define be32toh(x) ntohl(x)
  71. # define le32toh(x) (x)
  72. # define htobe64(x) htonll(x)
  73. # define htole64(x) (x)
  74. # define be64toh(x) ntohll(x)
  75. # define le64toh(x) (x)
  76. # elif BYTE_ORDER == BIG_ENDIAN /* that would be xbox 360 */
  77. # define htobe16(x) (x)
  78. # define htole16(x) __builtin_bswap16(x)
  79. # define be16toh(x) (x)
  80. # define le16toh(x) __builtin_bswap16(x)
  81. # define htobe32(x) (x)
  82. # define htole32(x) __builtin_bswap32(x)
  83. # define be32toh(x) (x)
  84. # define le32toh(x) __builtin_bswap32(x)
  85. # define htobe64(x) (x)
  86. # define htole64(x) __builtin_bswap64(x)
  87. # define be64toh(x) (x)
  88. # define le64toh(x) __builtin_bswap64(x)
  89. # else
  90. # error byte order not supported
  91. # endif
  92. # define __BYTE_ORDER BYTE_ORDER
  93. # define __BIG_ENDIAN BIG_ENDIAN
  94. # define __LITTLE_ENDIAN LITTLE_ENDIAN
  95. # define __PDP_ENDIAN PDP_ENDIAN
  96. #elif defined(__sun) && defined(__SVR4) /* Solaris */
  97. # include <sys/byteorder.h>
  98. # define htobe16(x) BE_16(x)
  99. # define htole16(x) LE_16(x)
  100. # define be16toh(x) BE_16(x)
  101. # define le16toh(x) LE_16(x)
  102. # define htobe32(x) BE_32(x)
  103. # define htole32(x) LE_32(x)
  104. # define be32toh(x) BE_32(x)
  105. # define le32toh(x) LE_32(x)
  106. # define htobe64(x) BE_64(x)
  107. # define htole64(x) LE_64(x)
  108. # define be64toh(x) BE_64(x)
  109. # define le64toh(x) LE_64(x)
  110. #else
  111. # error platform not supported
  112. #endif
  113. #endif