pa_endianness.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef PA_ENDIANNESS_H
  2. #define PA_ENDIANNESS_H
  3. /*
  4. * $Id: pa_endianness.h 1324 2008-01-27 02:03:30Z bjornroche $
  5. * Portable Audio I/O Library current platform endianness macros
  6. *
  7. * Based on the Open Source API proposed by Ross Bencina
  8. * Copyright (c) 1999-2002 Phil Burk, Ross Bencina
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining
  11. * a copy of this software and associated documentation files
  12. * (the "Software"), to deal in the Software without restriction,
  13. * including without limitation the rights to use, copy, modify, merge,
  14. * publish, distribute, sublicense, and/or sell copies of the Software,
  15. * and to permit persons to whom the Software is furnished to do so,
  16. * subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be
  19. * included in all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  25. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  26. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. */
  29. /*
  30. * The text above constitutes the entire PortAudio license; however,
  31. * the PortAudio community also makes the following non-binding requests:
  32. *
  33. * Any person wishing to distribute modifications to the Software is
  34. * requested to send the modifications to the original developer so that
  35. * they can be incorporated into the canonical version. It is also
  36. * requested that these non-binding requests be included along with the
  37. * license above.
  38. */
  39. /** @file
  40. @ingroup common_src
  41. @brief Configure endianness symbols for the target processor.
  42. Arrange for either the PA_LITTLE_ENDIAN or PA_BIG_ENDIAN preprocessor symbols
  43. to be defined. The one that is defined reflects the endianness of the target
  44. platform and may be used to implement conditional compilation of byte-order
  45. dependent code.
  46. If either PA_LITTLE_ENDIAN or PA_BIG_ENDIAN is defined already, then no attempt
  47. is made to override that setting. This may be useful if you have a better way
  48. of determining the platform's endianness. The autoconf mechanism uses this for
  49. example.
  50. A PA_VALIDATE_ENDIANNESS macro is provided to compare the compile time
  51. and runtime endiannes and raise an assertion if they don't match.
  52. */
  53. #ifdef __cplusplus
  54. extern "C"
  55. {
  56. #endif /* __cplusplus */
  57. /* If this is an apple, we need to do detect endianness this way */
  58. #if defined(__APPLE__)
  59. /* we need to do some endian detection that is sensitive to harware arch */
  60. #if defined(__LITTLE_ENDIAN__)
  61. #if !defined( PA_LITTLE_ENDIAN )
  62. #define PA_LITTLE_ENDIAN
  63. #endif
  64. #if defined( PA_BIG_ENDIAN )
  65. #undef PA_BIG_ENDIAN
  66. #endif
  67. #else
  68. #if !defined( PA_BIG_ENDIAN )
  69. #define PA_BIG_ENDIAN
  70. #endif
  71. #if defined( PA_LITTLE_ENDIAN )
  72. #undef PA_LITTLE_ENDIAN
  73. #endif
  74. #endif
  75. #else
  76. /* this is not an apple, so first check the existing defines, and, failing that,
  77. detect well-known architechtures. */
  78. #if defined(PA_LITTLE_ENDIAN) || defined(PA_BIG_ENDIAN)
  79. /* endianness define has been set externally, such as by autoconf */
  80. #if defined(PA_LITTLE_ENDIAN) && defined(PA_BIG_ENDIAN)
  81. #error both PA_LITTLE_ENDIAN and PA_BIG_ENDIAN have been defined externally to pa_endianness.h - only one endianness at a time please
  82. #endif
  83. #else
  84. /* endianness define has not been set externally */
  85. /* set PA_LITTLE_ENDIAN or PA_BIG_ENDIAN by testing well known platform specific defines */
  86. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(LITTLE_ENDIAN) || defined(__i386) || defined(_M_IX86) || defined(__x86_64__)
  87. #define PA_LITTLE_ENDIAN /* win32, assume intel byte order */
  88. #else
  89. #define PA_BIG_ENDIAN
  90. #endif
  91. #endif
  92. #if !defined(PA_LITTLE_ENDIAN) && !defined(PA_BIG_ENDIAN)
  93. /*
  94. If the following error is raised, you either need to modify the code above
  95. to automatically determine the endianness from other symbols defined on your
  96. platform, or define either PA_LITTLE_ENDIAN or PA_BIG_ENDIAN externally.
  97. */
  98. #error pa_endianness.h was unable to automatically determine the endianness of the target platform
  99. #endif
  100. #endif
  101. /* PA_VALIDATE_ENDIANNESS compares the compile time and runtime endianness,
  102. and raises an assertion if they don't match. <assert.h> must be included in
  103. the context in which this macro is used.
  104. */
  105. #if defined(NDEBUG)
  106. #define PA_VALIDATE_ENDIANNESS
  107. #else
  108. #if defined(PA_LITTLE_ENDIAN)
  109. #define PA_VALIDATE_ENDIANNESS \
  110. { \
  111. const long nativeOne = 1; \
  112. assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 1 ); \
  113. }
  114. #elif defined(PA_BIG_ENDIAN)
  115. #define PA_VALIDATE_ENDIANNESS \
  116. { \
  117. const long nativeOne = 1; \
  118. assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 0 ); \
  119. }
  120. #endif
  121. #endif
  122. #ifdef __cplusplus
  123. }
  124. #endif /* __cplusplus */
  125. #endif /* PA_ENDIANNESS_H */