selftest: Fix flapping samba.dsdb test
[Samba.git] / third_party / cmocka / cmocka_private.h
blobd20d841aed564f774ec441867a838709d4e1ba0f
1 /*
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_
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include <stdint.h>
26 #ifdef _WIN32
27 #include <windows.h>
29 # ifdef _MSC_VER
30 # include <stdio.h> /* _snprintf */
32 # undef inline
33 # define inline __inline
35 # ifndef va_copy
36 # define va_copy(dest, src) (dest = src)
37 # endif
39 # define strcasecmp _stricmp
40 # define strncasecmp _strnicmp
42 # if defined(HAVE__SNPRINTF_S)
43 # undef snprintf
44 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
45 # else /* HAVE__SNPRINTF_S */
46 # if defined(HAVE__SNPRINTF)
47 # undef snprintf
48 # define snprintf _snprintf
49 # else /* HAVE__SNPRINTF */
50 # if !defined(HAVE_SNPRINTF)
51 # error "no snprintf compatible function found"
52 # endif /* HAVE_SNPRINTF */
53 # endif /* HAVE__SNPRINTF */
54 # endif /* HAVE__SNPRINTF_S */
56 # if defined(HAVE__VSNPRINTF_S)
57 # undef vsnprintf
58 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
59 # else /* HAVE__VSNPRINTF_S */
60 # if defined(HAVE__VSNPRINTF)
61 # undef vsnprintf
62 # define vsnprintf _vsnprintf
63 # else
64 # if !defined(HAVE_VSNPRINTF)
65 # error "No vsnprintf compatible function found"
66 # endif /* HAVE_VSNPRINTF */
67 # endif /* HAVE__VSNPRINTF */
68 # endif /* HAVE__VSNPRINTF_S */
69 # endif /* _MSC_VER */
72 * Backwards compatibility with headers shipped with Visual Studio 2005 and
73 * earlier.
75 WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
77 #ifndef PRIdS
78 # define PRIdS "Id"
79 #endif
81 #ifndef PRIu64
82 # define PRIu64 "I64u"
83 #endif
85 #ifndef PRIuMAX
86 # define PRIuMAX PRIu64
87 #endif
89 #ifndef PRIxMAX
90 #define PRIxMAX "I64x"
91 #endif
93 #ifndef PRIXMAX
94 #define PRIXMAX "I64X"
95 #endif
97 #else /* _WIN32 */
99 #ifndef __PRI64_PREFIX
100 # if __WORDSIZE == 64
101 # define __PRI64_PREFIX "l"
102 # else
103 # define __PRI64_PREFIX "ll"
104 # endif
105 #endif
107 #ifndef PRIdS
108 # define PRIdS "zd"
109 #endif
111 #ifndef PRIu64
112 # define PRIu64 __PRI64_PREFIX "u"
113 #endif
115 #ifndef PRIuMAX
116 # define PRIuMAX __PRI64_PREFIX "u"
117 #endif
119 #ifndef PRIxMAX
120 #define PRIxMAX __PRI64_PREFIX "x"
121 #endif
123 #ifndef PRIXMAX
124 #define PRIXMAX __PRI64_PREFIX "X"
125 #endif
127 #endif /* _WIN32 */
129 /** Free memory space */
130 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
132 /** Zero a structure */
133 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
135 /** Zero a structure given a pointer to the structure */
136 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
138 /** Get the size of an array */
139 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
141 /** Overwrite the complete string with 'X' */
142 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
145 * This is a hack to fix warnings. The idea is to use this everywhere that we
146 * get the "discarding const" warning by the compiler. That doesn't actually
147 * fix the real issue, but marks the place and you can search the code for
148 * discard_const.
150 * Please use this macro only when there is no other way to fix the warning.
151 * We should use this function in only in a very few places.
153 * Also, please call this via the discard_const_p() macro interface, as that
154 * makes the return type safe.
156 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
159 * Type-safe version of discard_const
161 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
163 #endif /* CMOCKA_PRIVATE_H_ */