1 /* AbiSource Program Utilities 2 * Copyright (C) 2001 Tomas Frydrych 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 * 02110-1301 USA. 18 */ 19 20 /* 21 !!! PLEASE, USE ONLY C-STYLE COMMENTS IN THIS FILE !!! 22 */ 23 24 #ifndef UT_ENDIAN_H 25 #define UT_ENDIAN_H 26 27 /* autoconf checks */ 28 #ifdef CHECKED_ENDIANNESS 29 # if defined(WORDS_BIGENDIAN) 30 # define UT_BIG_ENDIAN 31 # else 32 # define UT_LITTLE_ENDIAN 33 # endif 34 #else 35 36 #if defined(__hpux) 37 /* #define UT_BIG_ENDIAN */ 38 #include <machine/param.h> 39 #if defined(_BIG_ENDIAN) 40 #define UT_BIG_ENDIAN 41 #endif 42 #if defined(_LITTLE_ENDIAN) 43 #define UT_LITTLE_ENDIAN 44 #endif 45 #elif defined(__QNXNTO__) 46 #include <sys/platform.h> 47 #if defined(__LITTLEENDIAN__) 48 #define UT_LITTLE_ENDIAN 49 #else 50 #define UT_BIG_ENDIAN 51 #endif 52 #elif defined(__FreeBSD__) || defined(__DragonFly__) 53 #include <machine/endian.h> 54 #if __BYTE_ORDER == __LITTLE_ENDIAN 55 #define UT_LITTLE_ENDIAN 56 #else 57 #define UT_BIG_ENDIAN 58 #endif 59 #elif defined(__sgi) 60 #include <sys/endian.h> 61 #if BYTE_ORDER == LITTLE_ENDIAN 62 #define UT_LITTLE_ENDIAN 63 #else 64 #define UT_BIG_ENDIAN 65 #endif 66 #elif defined(__MACH__) && defined(__APPLE__) 67 #if defined(__BIG_ENDIAN__) 68 #define UT_BIG_ENDIAN 69 #else 70 #define UT_LITTLE_ENDIAN 71 #endif 72 #elif defined(__sun) 73 #include <sys/isa_defs.h> 74 #if defined(_BIG_ENDIAN) 75 #define UT_BIG_ENDIAN 76 #elif defined(_LITTLE_ENDIAN) 77 #define UT_LITTLE_ENDIAN 78 #endif 79 #elif defined(__NetBSD__) || defined(__OpenBSD__) 80 #include <machine/endian.h> 81 #if BYTE_ORDER == LITTLE_ENDIAN 82 #define UT_LITTLE_ENDIAN 83 #elif BYTE_ORDER == BIG_ENDIAN 84 #define UT_BIG_ENDIAN 85 #endif 86 #elif defined(_AIX) 87 #include <sys/machine.h> 88 #if BYTE_ORDER == LITTLE_ENDIAN 89 #define UT_LITTLE_ENDIAN 90 #elif BYTE_ORDER == BIG_ENDIAN 91 #define UT_BIG_ENDIAN 92 #endif 93 #elif defined(__osf__) 94 #include <machine/endian.h> 95 #if BYTE_ORDER == LITTLE_ENDIAN 96 #define UT_LITTLE_ENDIAN 97 #elif BYTE_ORDER == BIG_ENDIAN 98 #define UT_BIG_ENDIAN 99 #endif 100 #elif defined(_WIN32) 101 /* We should probably do some check as the WinAPI could be on other computers */ 102 #if !defined(UT_LITTLE_ENDIAN) && !defined(UT_BIG_ENDIAN) 103 #define UT_LITTLE_ENDIAN 104 #endif 105 #else /* this is for Linux */ 106 #include <endian.h> 107 #if __BYTE_ORDER == __LITTLE_ENDIAN 108 #define UT_LITTLE_ENDIAN 109 #else 110 #define UT_BIG_ENDIAN 111 #endif 112 #endif 113 #endif 114 115 /* Make sure we got a definition for our platform: */ 116 #if defined(UT_BIG_ENDIAN) 117 #elif defined(UT_LITTLE_ENDIAN) 118 #else 119 #error Must define UT_BIG_ENDIAN or UT_LITTLE_ENDIAN in ut_endian.h 120 #endif 121 122 /*XP macros 123 124 convert single UCS character 125 x,y are pointers to UT_UCSChar 126 we will use a temporary variable, so that x and y 127 can be the same 128 */ 129 130 #ifdef UT_LITTLE_ENDIAN 131 #define LE2BE16(x,y) \ 132 char * lb1; \ 133 UT_UCSChar tucs; \ 134 tucs = * ((UT_UCSChar *)(x)); lb1 = (char*) (&tucs); \ 135 *((char*)(y)) = *(lb1+1); *(((char*)(y)+1)) = *lb1; 136 #else 137 #define LE2BE16(x,y) 138 #endif 139 140 #endif /*UT_ENDIAN_H*/ 141 142