• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_endian.h

Go to the documentation of this file.
00001 /* AbiSource Program Utilities
00002  * Copyright (C) 2001 Tomas Frydrych
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 /*
00021  !!! PLEASE, USE ONLY C-STYLE COMMENTS IN THIS FILE !!!
00022 */
00023 
00024 #ifndef UT_ENDIAN_H
00025 #define UT_ENDIAN_H
00026 
00027 /* autoconf checks */
00028 #ifdef CHECKED_ENDIANNESS
00029 #  if defined(WORDS_BIGENDIAN)
00030 #    define UT_BIG_ENDIAN
00031 #  else
00032 #    define UT_LITTLE_ENDIAN
00033 #  endif
00034 #else
00035 
00036 #if defined(__hpux)
00037     /* #define UT_BIG_ENDIAN */
00038     #include <machine/param.h>
00039     #if defined(_BIG_ENDIAN)
00040         #define UT_BIG_ENDIAN
00041     #endif
00042     #if defined(_LITTLE_ENDIAN)
00043         #define UT_LITTLE_ENDIAN
00044     #endif
00045 #elif defined(__QNXNTO__)
00046     #include <sys/platform.h>
00047     #if defined(__LITTLEENDIAN__)
00048         #define UT_LITTLE_ENDIAN
00049     #else
00050         #define UT_BIG_ENDIAN
00051     #endif
00052 #elif defined(__FreeBSD__)
00053     #include <machine/endian.h>
00054     #if __BYTE_ORDER == __LITTLE_ENDIAN
00055         #define UT_LITTLE_ENDIAN
00056     #else
00057         #define UT_BIG_ENDIAN
00058     #endif
00059 #elif defined(__sgi)
00060     #include <sys/endian.h>
00061     #if BYTE_ORDER == LITTLE_ENDIAN
00062         #define UT_LITTLE_ENDIAN
00063     #else
00064         #define UT_BIG_ENDIAN
00065     #endif
00066 #elif defined(__MACH__) && defined(__APPLE__)
00067     #if defined(__BIG_ENDIAN__)
00068         #define UT_BIG_ENDIAN
00069     #else
00070         #define UT_LITTLE_ENDIAN
00071     #endif
00072 #elif defined(__sun)
00073         #include <sys/isa_defs.h>
00074         #if defined(_BIG_ENDIAN)
00075                 #define UT_BIG_ENDIAN
00076         #elif defined(_LITTLE_ENDIAN)
00077                 #define UT_LITTLE_ENDIAN
00078         #endif
00079 #elif defined(__NetBSD__) || defined(__OpenBSD__)
00080     #include <machine/endian.h>
00081     #if BYTE_ORDER == LITTLE_ENDIAN
00082         #define UT_LITTLE_ENDIAN
00083     #elif BYTE_ORDER == BIG_ENDIAN
00084         #define UT_BIG_ENDIAN
00085     #endif
00086 #elif defined(_AIX)
00087         #include <sys/machine.h>
00088         #if BYTE_ORDER == LITTLE_ENDIAN
00089                 #define UT_LITTLE_ENDIAN
00090         #elif BYTE_ORDER == BIG_ENDIAN
00091                 #define UT_BIG_ENDIAN
00092         #endif
00093 #elif defined(__osf__)
00094         #include <machine/endian.h>
00095         #if BYTE_ORDER == LITTLE_ENDIAN
00096                 #define UT_LITTLE_ENDIAN
00097         #elif BYTE_ORDER == BIG_ENDIAN
00098                 #define UT_BIG_ENDIAN
00099         #endif
00100 #elif defined(_WIN32)
00101     /* We should probably do some check as the WinAPI could be on other computers */
00102     #if !defined(UT_LITTLE_ENDIAN) && !defined(UT_BIG_ENDIAN)
00103         #define UT_LITTLE_ENDIAN
00104     #endif
00105 #else /* this is for Linux */
00106     #include <endian.h>
00107     #if __BYTE_ORDER == __LITTLE_ENDIAN
00108         #define UT_LITTLE_ENDIAN
00109     #else
00110         #define UT_BIG_ENDIAN
00111     #endif
00112 #endif
00113 #endif
00114 
00115 /*  Make sure we got a definition for our platform:  */
00116 #if defined(UT_BIG_ENDIAN)
00117 #elif defined(UT_LITTLE_ENDIAN)
00118 #else
00119     #error Must define UT_BIG_ENDIAN or UT_LITTLE_ENDIAN in ut_endian.h
00120 #endif
00121 
00122 /*XP macros
00123 
00124  convert single UCS character
00125  x,y are pointers to UT_UCSChar
00126  we will use a temporary variable, so that x and y
00127  can be the same
00128 */
00129 
00130 #ifdef UT_LITTLE_ENDIAN
00131 #define LE2BE16(x,y)                                  \
00132 char * lb1;                                           \
00133 UT_UCSChar tucs;                                      \
00134 tucs = * ((UT_UCSChar *)(x)); lb1 = (char*) (&tucs);  \
00135 *((char*)(y)) = *(lb1+1); *(((char*)(y)+1)) = *lb1;
00136 #else
00137 #define LE2BE16(x,y)
00138 #endif
00139 
00140 #endif /*UT_ENDIAN_H*/
00141 

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1