2 * Copyright 2008 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef CMOCKA_PRIVATE_H_
18 #define CMOCKA_PRIVATE_H_
26 # include <stdio.h> /* _snprintf */
29 # define inline __inline
31 # define strcasecmp _stricmp
32 # define strncasecmp _strnicmp
34 # if defined(HAVE__SNPRINTF_S)
36 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
37 # else /* HAVE__SNPRINTF_S */
38 # if defined(HAVE__SNPRINTF)
40 # define snprintf _snprintf
41 # else /* HAVE__SNPRINTF */
42 # if !defined(HAVE_SNPRINTF)
43 # error "no snprintf compatible function found"
44 # endif /* HAVE_SNPRINTF */
45 # endif /* HAVE__SNPRINTF */
46 # endif /* HAVE__SNPRINTF_S */
48 # if defined(HAVE__VSNPRINTF_S)
50 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
51 # else /* HAVE__VSNPRINTF_S */
52 # if defined(HAVE__VSNPRINTF)
54 # define vsnprintf _vsnprintf
56 # if !defined(HAVE_VSNPRINTF)
57 # error "No vsnprintf compatible function found"
58 # endif /* HAVE_VSNPRINTF */
59 # endif /* HAVE__VSNPRINTF */
60 # endif /* HAVE__VSNPRINTF_S */
61 # endif /* _MSC_VER */
64 * Backwards compatibility with headers shipped with Visual Studio 2005 and
67 WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
74 # define PRIu64 "I64u"
78 # define PRIuMAX PRIu64
82 #define PRIxMAX "I64x"
86 #define PRIXMAX "I64X"
91 #ifndef __PRI64_PREFIX
93 # define __PRI64_PREFIX "l"
95 # define __PRI64_PREFIX "ll"
104 # define PRIu64 __PRI64_PREFIX "u"
108 # define PRIuMAX __PRI64_PREFIX "u"
112 #define PRIxMAX __PRI64_PREFIX "x"
116 #define PRIXMAX __PRI64_PREFIX "X"
122 /** Free memory space */
123 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
125 /** Zero a structure */
126 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
128 /** Zero a structure given a pointer to the structure */
129 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
131 /** Get the size of an array */
132 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
134 /** Overwrite the complete string with 'X' */
135 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
138 * This is a hack to fix warnings. The idea is to use this everywhere that we
139 * get the "discarding const" warning by the compiler. That doesn't actually
140 * fix the real issue, but marks the place and you can search the code for
143 * Please use this macro only when there is no other way to fix the warning.
144 * We should use this function in only in a very few places.
146 * Also, please call this via the discard_const_p() macro interface, as that
147 * makes the return type safe.
149 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
152 * Type-safe version of discard_const
154 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
156 #endif /* CMOCKA_PRIVATE_H_ */