xed-portability.h

Go to the documentation of this file.
00001 /*BEGIN_LEGAL 
00002 Intel Open Source License 
00003 
00004 Copyright (c) 2002-2015 Intel Corporation. All rights reserved.
00005  
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are
00008 met:
00009 
00010 Redistributions of source code must retain the above copyright notice,
00011 this list of conditions and the following disclaimer.  Redistributions
00012 in binary form must reproduce the above copyright notice, this list of
00013 conditions and the following disclaimer in the documentation and/or
00014 other materials provided with the distribution.  Neither the name of
00015 the Intel Corporation nor the names of its contributors may be used to
00016 endorse or promote products derived from this software without
00017 specific prior written permission.
00018  
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00023 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 END_LEGAL */
00033 
00034 #ifndef _XED_PORTABILITY_H_
00035 # define _XED_PORTABILITY_H_
00036 # include "xed-common-hdrs.h"
00037 # include "xed-types.h"
00038 
00039 
00040 #define XED_STATIC_CAST(x,y) ((x) (y))
00041 #define XED_REINTERPRET_CAST(x,y) ((x) (y))
00042 #define XED_CAST(x,y) ((x) (y))
00043 
00044 
00045     
00046 XED_DLL_EXPORT xed_uint_t xed_strlen(const char* s);
00047 XED_DLL_EXPORT void xed_strcat(char* dst, const char* src);
00048 XED_DLL_EXPORT void xed_strcpy(char* dst, const char* src);
00049 
00052 XED_DLL_EXPORT int xed_strncpy(char* dst, const char* src,  int len);
00053 
00056 XED_DLL_EXPORT int xed_strncat(char* dst, const char* src,  int len);
00057 
00058 #if defined(__INTEL_COMPILER)
00059 # if defined(_WIN32) && defined(_MSC_VER)
00060 #   if _MSC_VER >= 1400
00061 #     define XED_MSVC8_OR_LATER 1
00062 #   endif
00063 # endif
00064 #endif
00065 
00066 /* recognize VC98 */
00067 #if !defined(__INTEL_COMPILER)
00068 # if defined(_WIN32) && defined(_MSC_VER)
00069 #   if _MSC_VER == 1200
00070 #     define XED_MSVC6 1
00071 #   endif
00072 # endif
00073 # if defined(_WIN32) && defined(_MSC_VER)
00074 #   if _MSC_VER == 1310
00075 #     define XED_MSVC7 1
00076 #   endif
00077 # endif
00078 # if defined(_WIN32) && defined(_MSC_VER)
00079 #   if _MSC_VER >= 1400
00080 #     define XED_MSVC8_OR_LATER 1
00081 #   endif
00082 #   if _MSC_VER == 1400
00083 #     define XED_MSVC8 1
00084 #   endif
00085 #   if _MSC_VER == 1500
00086 #     define XED_MSVC9 1
00087 #   endif
00088 #   if _MSC_VER >= 1500
00089 #     define XED_MSVC9_OR_LATER 1
00090 #   endif
00091 #   if _MSC_VER == 1600
00092 #     define XED_MSVC10 1
00093 #   endif
00094 #   if _MSC_VER >= 1600
00095 #     define XED_MSVC10_OR_LATER 1
00096 #   endif
00097 # endif
00098 #endif
00099 
00100 /* I've had compatibilty problems here so I'm using a trivial indirection */
00101 #if defined(__GNUC__)
00102 #  if defined(__CYGWIN__)
00103       /* cygwin's gcc 3.4.4 on windows  complains */
00104 #    define XED_FMT_X "%lx"
00105 #    define XED_FMT_08X "%08lx"
00106 #    define XED_FMT_D "%ld"
00107 #    define XED_FMT_U "%lu"
00108 #    define XED_FMT_9U "%9lu"
00109 #  else
00110 #    define XED_FMT_X "%x"
00111 #    define XED_FMT_08X "%08x"
00112 #    define XED_FMT_D "%d"
00113 #    define XED_FMT_U "%u"
00114 #    define XED_FMT_9U "%9u"
00115 #  endif
00116 #else
00117 #  define XED_FMT_X "%x"
00118 #  define XED_FMT_08X "%08x"
00119 #  define XED_FMT_D "%d"
00120 #  define XED_FMT_U "%u"
00121 #  define XED_FMT_9U "%9u"
00122 #endif
00123 
00124 // Go write portable code... Sigh
00125 #if defined(__APPLE__)  // clang *32b* and 64b
00126 # define XED_FMT_SIZET "%lu"
00127 #elif defined(__LP64__)  // 64b gcc, icc
00128 # define XED_FMT_SIZET "%lu"
00129 #elif defined (_M_X64)   // 64b msvs, ICL
00130   // MSVS/x64 accepts %llu or %lu, icl/x64 does not)
00131 # define XED_FMT_SIZET "%llu"
00132 #else  // 32b everything else
00133 # define XED_FMT_SIZET "%u"
00134 #endif
00135 
00136 #if defined(__GNUC__) && defined(__LP64__) && !defined(__APPLE__)
00137 # define XED_FMT_LX "%lx"
00138 # define XED_FMT_LU "%lu"
00139 # define XED_FMT_LU12 "%12lu"
00140 # define XED_FMT_LD "%ld"
00141 # define XED_FMT_LX16 "%016lx"
00142 #else
00143 # define XED_FMT_LX "%llx"
00144 # define XED_FMT_LU "%llu"
00145 # define XED_FMT_LU12 "%12llu"
00146 # define XED_FMT_LD "%lld"
00147 # define XED_FMT_LX16 "%016llx"
00148 #endif
00149 
00150 #if defined(__LP64__) || defined (_M_X64) 
00151 # define XED_64B 1
00152 #endif
00153 
00154 #if defined(_M_IA64)
00155 # define XED_IPF
00156 # define XED_FMT_SIZET "%lu"
00157 #endif
00158 
00159 #if defined(__GNUC__)    
00160      /* gcc4.2.x has a bug with c99/gnu99 inlining */
00161 #  if __GNUC__ == 4 && __GNUC_MINOR__ == 2
00162 #    define XED_INLINE inline
00163 #  else
00164 #    if __GNUC__ == 2
00165 #       define XED_INLINE 
00166 #    else 
00167 #       define XED_INLINE inline
00168 #    endif
00169 # endif
00170 # define XED_NORETURN __attribute__ ((noreturn))
00171 # if __GNUC__ == 2
00172 #   define XED_NOINLINE 
00173 # else
00174 #   define XED_NOINLINE __attribute__ ((noinline))
00175 # endif
00176 #else
00177 # define XED_INLINE __inline
00178 # if defined(XED_MSVC6)
00179 #   define XED_NOINLINE 
00180 # else
00181 #   define XED_NOINLINE __declspec(noinline)
00182 # endif
00183 # define XED_NORETURN __declspec(noreturn)
00184 #endif
00185 
00186 
00187 
00188 #define XED_MAX(a, b) (((a) > (b)) ? (a):(b))
00189 #define XED_MIN(a, b) (((a) < (b)) ? (a):(b))
00190 
00191 
00192 
00193 
00194 #endif  // _XED_PORTABILITY_H_
00195 

Generated on Wed Jan 21 02:15:49 2015 for XED by  doxygen 1.4.6