| 1 | #ifndef PA_ENDIANNESS_H |
| 2 | #define PA_ENDIANNESS_H |
| 3 | /* |
| 4 | * $Id: pa_endianness.h,v 1.1 2006/06/10 21:30:55 dmazzoni Exp $ |
| 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 | * Any person wishing to distribute modifications to the Software is |
| 22 | * requested to send the modifications to the original developer so that |
| 23 | * they can be incorporated into the canonical version. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 28 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
| 29 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 30 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 31 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 32 | */ |
| 33 | |
| 34 | /** @file |
| 35 | @brief Configure endianness symbols for the target processor. |
| 36 | |
| 37 | Arrange for either the PA_LITTLE_ENDIAN or PA_BIG_ENDIAN preprocessor symbols |
| 38 | to be defined. The one that is defined reflects the endianness of the target |
| 39 | platform and may be used to implement conditional compilation of byte-order |
| 40 | dependent code. |
| 41 | |
| 42 | If either PA_LITTLE_ENDIAN or PA_BIG_ENDIAN is defined already, then no attempt |
| 43 | is made to override that setting. This may be useful if you have a better way |
| 44 | of determining the platform's endianness. The autoconf mechanism uses this for |
| 45 | example. |
| 46 | |
| 47 | A PA_VALIDATE_ENDIANNESS macro is provided to compare the compile time |
| 48 | and runtime endiannes and raise an assertion if they don't match. |
| 49 | */ |
| 50 | |
| 51 | |
| 52 | #ifdef __cplusplus |
| 53 | extern "C" |
| 54 | { |
| 55 | #endif /* __cplusplus */ |
| 56 | |
| 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 | |
| 79 | #if defined(PA_LITTLE_ENDIAN) || defined(PA_BIG_ENDIAN) |
| 80 | /* endianness define has been set externally, such as by autoconf */ |
| 81 | |
| 82 | #if defined(PA_LITTLE_ENDIAN) && defined(PA_BIG_ENDIAN) |
| 83 | #error both PA_LITTLE_ENDIAN and PA_BIG_ENDIAN have been defined externally to pa_endianness.h - only one endianness at a time please |
| 84 | #endif |
| 85 | |
| 86 | #endif |
| 87 | /* endianness define has not been set externally */ |
| 88 | |
| 89 | /* set PA_LITTLE_ENDIAN or PA_BIG_ENDIAN by testing well known platform specific defines */ |
| 90 | |
| 91 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(LITTLE_ENDIAN) || defined(__i386) || defined(_M_IX86) || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) |
| 92 | #define PA_LITTLE_ENDIAN /* win32, assume intel byte order */ |
| 93 | #else |
| 94 | #define PA_BIG_ENDIAN |
| 95 | #endif |
| 96 | |
| 97 | #if !defined(PA_LITTLE_ENDIAN) && !defined(PA_BIG_ENDIAN) |
| 98 | /* |
| 99 | If the following error is raised, you either need to modify the code above |
| 100 | to automatically determine the endianness from other symbols defined on your |
| 101 | platform, or define either PA_LITTLE_ENDIAN or PA_BIG_ENDIAN externally. |
| 102 | */ |
| 103 | #error pa_endianness.h was unable to automatically determine the endianness of the target platform |
| 104 | #endif |
| 105 | |
| 106 | #endif |
| 107 | |
| 108 | /* PA_VALIDATE_ENDIANNESS compares the compile time and runtime endianness, |
| 109 | and raises an assertion if they don't match. <assert.h> must be included in |
| 110 | the context in which this macro is used. |
| 111 | */ |
| 112 | #if defined(PA_LITTLE_ENDIAN) |
| 113 | #define PA_VALIDATE_ENDIANNESS \ |
| 114 | { \ |
| 115 | const long nativeOne = 1; \ |
| 116 | assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 1 ); \ |
| 117 | } |
| 118 | #elif defined(PA_BIG_ENDIAN) |
| 119 | #define PA_VALIDATE_ENDIANNESS \ |
| 120 | { \ |
| 121 | const long nativeOne = 1; \ |
| 122 | assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 0 ); \ |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | |
| 127 | #ifdef __cplusplus |
| 128 | } |
| 129 | #endif /* __cplusplus */ |
| 130 | #endif /* PA_ENDIANNESS_H */ |