cmocka
1.0.1
|
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 #include "config.h" 00021 00022 #include <stdint.h> 00023 00024 #ifdef _WIN32 00025 #include <windows.h> 00026 00027 # ifdef _MSC_VER 00028 # include <stdio.h> /* _snprintf */ 00029 00030 # undef inline 00031 # define inline __inline 00032 00033 # define strcasecmp _stricmp 00034 # define strncasecmp _strnicmp 00035 00036 # if defined(HAVE__SNPRINTF_S) 00037 # undef snprintf 00038 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__) 00039 # else /* HAVE__SNPRINTF_S */ 00040 # if defined(HAVE__SNPRINTF) 00041 # undef snprintf 00042 # define snprintf _snprintf 00043 # else /* HAVE__SNPRINTF */ 00044 # if !defined(HAVE_SNPRINTF) 00045 # error "no snprintf compatible function found" 00046 # endif /* HAVE_SNPRINTF */ 00047 # endif /* HAVE__SNPRINTF */ 00048 # endif /* HAVE__SNPRINTF_S */ 00049 00050 # if defined(HAVE__VSNPRINTF_S) 00051 # undef vsnprintf 00052 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v)) 00053 # else /* HAVE__VSNPRINTF_S */ 00054 # if defined(HAVE__VSNPRINTF) 00055 # undef vsnprintf 00056 # define vsnprintf _vsnprintf 00057 # else 00058 # if !defined(HAVE_VSNPRINTF) 00059 # error "No vsnprintf compatible function found" 00060 # endif /* HAVE_VSNPRINTF */ 00061 # endif /* HAVE__VSNPRINTF */ 00062 # endif /* HAVE__VSNPRINTF_S */ 00063 # endif /* _MSC_VER */ 00064 00065 /* 00066 * Backwards compatibility with headers shipped with Visual Studio 2005 and 00067 * earlier. 00068 */ 00069 WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID); 00070 00071 #ifndef PRIdS 00072 # define PRIdS "Id" 00073 #endif 00074 00075 #ifndef PRIu64 00076 # define PRIu64 "I64u" 00077 #endif 00078 00079 #ifndef PRIuMAX 00080 # define PRIuMAX PRIu64 00081 #endif 00082 00083 #ifndef PRIxMAX 00084 #define PRIxMAX "I64x" 00085 #endif 00086 00087 #ifndef PRIXMAX 00088 #define PRIXMAX "I64X" 00089 #endif 00090 00091 #else /* _WIN32 */ 00092 00093 #ifndef __PRI64_PREFIX 00094 # if __WORDSIZE == 64 00095 # define __PRI64_PREFIX "l" 00096 # else 00097 # define __PRI64_PREFIX "ll" 00098 # endif 00099 #endif 00100 00101 #ifndef PRIdS 00102 # define PRIdS "zd" 00103 #endif 00104 00105 #ifndef PRIu64 00106 # define PRIu64 __PRI64_PREFIX "u" 00107 #endif 00108 00109 #ifndef PRIuMAX 00110 # define PRIuMAX __PRI64_PREFIX "u" 00111 #endif 00112 00113 #ifndef PRIxMAX 00114 #define PRIxMAX __PRI64_PREFIX "x" 00115 #endif 00116 00117 #ifndef PRIXMAX 00118 #define PRIXMAX __PRI64_PREFIX "X" 00119 #endif 00120 00121 #endif /* _WIN32 */ 00122 00124 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) 00125 00127 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) 00128 00130 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) 00131 00133 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) 00134 00136 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0) 00137 00150 #define discard_const(ptr) ((void *)((uintptr_t)(ptr))) 00151 00155 #define discard_const_p(type, ptr) ((type *)discard_const(ptr)) 00156 00157 #endif /* CMOCKA_PRIVATE_H_ */