00001 #ifndef PA_ENDIANNESS_H 00002 #define PA_ENDIANNESS_H 00003 /* 00004 * $Id: pa_endianness.h 1097 2006-08-26 08:27:53Z rossb $ 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 #endif 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) 00101 #define PA_LITTLE_ENDIAN /* win32, assume intel byte order */ 00102 #else 00103 #define PA_BIG_ENDIAN 00104 #endif 00105 00106 #if !defined(PA_LITTLE_ENDIAN) && !defined(PA_BIG_ENDIAN) 00107 /* 00108 If the following error is raised, you either need to modify the code above 00109 to automatically determine the endianness from other symbols defined on your 00110 platform, or define either PA_LITTLE_ENDIAN or PA_BIG_ENDIAN externally. 00111 */ 00112 #error pa_endianness.h was unable to automatically determine the endianness of the target platform 00113 #endif 00114 00115 #endif 00116 00117 /* PA_VALIDATE_ENDIANNESS compares the compile time and runtime endianness, 00118 and raises an assertion if they don't match. <assert.h> must be included in 00119 the context in which this macro is used. 00120 */ 00121 #if defined(PA_LITTLE_ENDIAN) 00122 #define PA_VALIDATE_ENDIANNESS \ 00123 { \ 00124 const long nativeOne = 1; \ 00125 assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 1 ); \ 00126 } 00127 #elif defined(PA_BIG_ENDIAN) 00128 #define PA_VALIDATE_ENDIANNESS \ 00129 { \ 00130 const long nativeOne = 1; \ 00131 assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 0 ); \ 00132 } 00133 #endif 00134 00135 00136 #ifdef __cplusplus 00137 } 00138 #endif /* __cplusplus */ 00139 #endif /* PA_ENDIANNESS_H */