cmocka  1.1.1
include/cmocka_private.h
00001 /*
00002  * Copyright 2008 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef CMOCKA_PRIVATE_H_
00018 #define CMOCKA_PRIVATE_H_
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include "config.h"
00022 #endif
00023 
00024 #include <stdint.h>
00025 
00026 #ifdef _WIN32
00027 #include <windows.h>
00028 
00029 # ifdef _MSC_VER
00030 # include <stdio.h> /* _snprintf */
00031 
00032 #  undef inline
00033 #  define inline __inline
00034 
00035 #  ifndef va_copy
00036 #   define va_copy(dest, src) (dest = src)
00037 #  endif
00038 
00039 #  define strcasecmp _stricmp
00040 #  define strncasecmp _strnicmp
00041 
00042 #  if defined(HAVE__SNPRINTF_S)
00043 #   undef snprintf
00044 #   define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
00045 #  else /* HAVE__SNPRINTF_S */
00046 #   if defined(HAVE__SNPRINTF)
00047 #     undef snprintf
00048 #     define snprintf _snprintf
00049 #   else /* HAVE__SNPRINTF */
00050 #    if !defined(HAVE_SNPRINTF)
00051 #     error "no snprintf compatible function found"
00052 #    endif /* HAVE_SNPRINTF */
00053 #   endif /* HAVE__SNPRINTF */
00054 #  endif /* HAVE__SNPRINTF_S */
00055 
00056 #  if defined(HAVE__VSNPRINTF_S)
00057 #   undef vsnprintf
00058 #   define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
00059 #  else /* HAVE__VSNPRINTF_S */
00060 #   if defined(HAVE__VSNPRINTF)
00061 #    undef vsnprintf
00062 #    define vsnprintf _vsnprintf
00063 #   else
00064 #    if !defined(HAVE_VSNPRINTF)
00065 #     error "No vsnprintf compatible function found"
00066 #    endif /* HAVE_VSNPRINTF */
00067 #   endif /* HAVE__VSNPRINTF */
00068 #  endif /* HAVE__VSNPRINTF_S */
00069 # endif /* _MSC_VER */
00070 
00071 /*
00072  * Backwards compatibility with headers shipped with Visual Studio 2005 and
00073  * earlier.
00074  */
00075 WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
00076 
00077 #ifndef PRIdS
00078 # define PRIdS "Id"
00079 #endif
00080 
00081 #ifndef PRIu64
00082 # define PRIu64 "I64u"
00083 #endif
00084 
00085 #ifndef PRIuMAX
00086 # define PRIuMAX PRIu64
00087 #endif
00088 
00089 #ifndef PRIxMAX
00090 #define PRIxMAX "I64x"
00091 #endif
00092 
00093 #ifndef PRIXMAX
00094 #define PRIXMAX "I64X"
00095 #endif
00096 
00097 #else /* _WIN32 */
00098 
00099 #ifndef __PRI64_PREFIX
00100 # if __WORDSIZE == 64
00101 #  define __PRI64_PREFIX "l"
00102 # else
00103 #  define __PRI64_PREFIX "ll"
00104 # endif
00105 #endif
00106 
00107 #ifndef PRIdS
00108 # define PRIdS "zd"
00109 #endif
00110 
00111 #ifndef PRIu64
00112 # define PRIu64 __PRI64_PREFIX "u"
00113 #endif
00114 
00115 #ifndef PRIuMAX
00116 # define PRIuMAX __PRI64_PREFIX "u"
00117 #endif
00118 
00119 #ifndef PRIxMAX
00120 #define PRIxMAX __PRI64_PREFIX "x"
00121 #endif
00122 
00123 #ifndef PRIXMAX
00124 #define PRIXMAX __PRI64_PREFIX "X"
00125 #endif
00126 
00127 #endif /* _WIN32 */
00128 
00130 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
00131 
00133 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
00134 
00136 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
00137 
00139 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
00140 
00142 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
00143 
00156 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
00157 
00161 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
00162 
00163 #endif /* CMOCKA_PRIVATE_H_ */