00001 #ifndef PA_ENDIANNESS_H 00002 #define PA_ENDIANNESS_H 00003 /* 00004 * $Id: pa_endianness.h 1216 2007-06-10 09:26:00Z aknudsen $ 00005 * Portable Audio I/O Library current platform endianness macros 00006 * 00007 * Based on the Open Source API proposed by Ross Bencina 00008 * Copyright (c) 1999-2002 Phil Burk, Ross Bencina 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining 00011 * a copy of this software and associated documentation files 00012 * (the "Software"), to deal in the Software without restriction, 00013 * including without limitation the rights to use, copy, modify, merge, 00014 * publish, distribute, sublicense, and/or sell copies of the Software, 00015 * and to permit persons to whom the Software is furnished to do so, 00016 * subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be 00019 * included in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00023 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00024 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 00025 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 00026 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00027 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00028 */ 00029 00030 /* 00031 * The text above constitutes the entire PortAudio license; however, 00032 * the PortAudio community also makes the following non-binding requests: 00033 * 00034 * Any person wishing to distribute modifications to the Software is 00035 * requested to send the modifications to the original developer so that 00036 * they can be incorporated into the canonical version. It is also 00037 * requested that these non-binding requests be included along with the 00038 * license above. 00039 */ 00040 00061 #ifdef __cplusplus 00062 extern "C" 00063 { 00064 #endif /* __cplusplus */ 00065 00066 /* If this is an apple, we need to do detect endianness this way */ 00067 #if defined(__APPLE__) 00068 /* we need to do some endian detection that is sensitive to harware arch */ 00069 #if defined(__LITTLE_ENDIAN__) 00070 #if !defined( PA_LITTLE_ENDIAN ) 00071 #define PA_LITTLE_ENDIAN 00072 #endif 00073 #if defined( PA_BIG_ENDIAN ) 00074 #undef PA_BIG_ENDIAN 00075 #endif 00076 #else 00077 #if !defined( PA_BIG_ENDIAN ) 00078 #define PA_BIG_ENDIAN 00079 #endif 00080 #if defined( PA_LITTLE_ENDIAN ) 00081 #undef PA_LITTLE_ENDIAN 00082 #endif 00083 #endif 00084 #else 00085 /* this is not an apple, so first check the existing defines, and, failing that, 00086 detect well-known architechtures. */ 00087 00088 #if defined(PA_LITTLE_ENDIAN) || defined(PA_BIG_ENDIAN) 00089 /* endianness define has been set externally, such as by autoconf */ 00090 00091 #if defined(PA_LITTLE_ENDIAN) && defined(PA_BIG_ENDIAN) 00092 #error both PA_LITTLE_ENDIAN and PA_BIG_ENDIAN have been defined externally to pa_endianness.h - only one endianness at a time please 00093 #endif 00094 00095 #else 00096 /* endianness define has not been set externally */ 00097 00098 /* set PA_LITTLE_ENDIAN or PA_BIG_ENDIAN by testing well known platform specific defines */ 00099 00100 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(LITTLE_ENDIAN) || defined(__i386) || defined(_M_IX86) || defined(__x86_64__) 00101 #define PA_LITTLE_ENDIAN /* win32, assume intel byte order */ 00102 #else 00103 #define PA_BIG_ENDIAN 00104 #endif 00105 #endif 00106 00107 #if !defined(PA_LITTLE_ENDIAN) && !defined(PA_BIG_ENDIAN) 00108 /* 00109 If the following error is raised, you either need to modify the code above 00110 to automatically determine the endianness from other symbols defined on your 00111 platform, or define either PA_LITTLE_ENDIAN or PA_BIG_ENDIAN externally. 00112 */ 00113 #error pa_endianness.h was unable to automatically determine the endianness of the target platform 00114 #endif 00115 00116 #endif 00117 00118 00119 /* PA_VALIDATE_ENDIANNESS compares the compile time and runtime endianness, 00120 and raises an assertion if they don't match. <assert.h> must be included in 00121 the context in which this macro is used. 00122 */ 00123 #if defined(PA_LITTLE_ENDIAN) 00124 #define PA_VALIDATE_ENDIANNESS \ 00125 { \ 00126 const long nativeOne = 1; \ 00127 assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 1 ); \ 00128 } 00129 #elif defined(PA_BIG_ENDIAN) 00130 #define PA_VALIDATE_ENDIANNESS \ 00131 { \ 00132 const long nativeOne = 1; \ 00133 assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 0 ); \ 00134 } 00135 #endif 00136 00137 00138 #ifdef __cplusplus 00139 } 00140 #endif /* __cplusplus */ 00141 #endif /* PA_ENDIANNESS_H */