cmocka  1.0.1
cmocka_private.h
1 /*
2  * Copyright 2008 Google Inc.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #ifndef CMOCKA_PRIVATE_H_
18 #define CMOCKA_PRIVATE_H_
19 
20 #include "config.h"
21 
22 #include <stdint.h>
23 
24 #ifdef _WIN32
25 #include <windows.h>
26 
27 # ifdef _MSC_VER
28 # include <stdio.h> /* _snprintf */
29 
30 # undef inline
31 # define inline __inline
32 
33 # define strcasecmp _stricmp
34 # define strncasecmp _strnicmp
35 
36 # if defined(HAVE__SNPRINTF_S)
37 # undef snprintf
38 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
39 # else /* HAVE__SNPRINTF_S */
40 # if defined(HAVE__SNPRINTF)
41 # undef snprintf
42 # define snprintf _snprintf
43 # else /* HAVE__SNPRINTF */
44 # if !defined(HAVE_SNPRINTF)
45 # error "no snprintf compatible function found"
46 # endif /* HAVE_SNPRINTF */
47 # endif /* HAVE__SNPRINTF */
48 # endif /* HAVE__SNPRINTF_S */
49 
50 # if defined(HAVE__VSNPRINTF_S)
51 # undef vsnprintf
52 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
53 # else /* HAVE__VSNPRINTF_S */
54 # if defined(HAVE__VSNPRINTF)
55 # undef vsnprintf
56 # define vsnprintf _vsnprintf
57 # else
58 # if !defined(HAVE_VSNPRINTF)
59 # error "No vsnprintf compatible function found"
60 # endif /* HAVE_VSNPRINTF */
61 # endif /* HAVE__VSNPRINTF */
62 # endif /* HAVE__VSNPRINTF_S */
63 # endif /* _MSC_VER */
64 
65 /*
66  * Backwards compatibility with headers shipped with Visual Studio 2005 and
67  * earlier.
68  */
69 WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
70 
71 #ifndef PRIdS
72 # define PRIdS "Id"
73 #endif
74 
75 #ifndef PRIu64
76 # define PRIu64 "I64u"
77 #endif
78 
79 #ifndef PRIuMAX
80 # define PRIuMAX PRIu64
81 #endif
82 
83 #ifndef PRIxMAX
84 #define PRIxMAX "I64x"
85 #endif
86 
87 #ifndef PRIXMAX
88 #define PRIXMAX "I64X"
89 #endif
90 
91 #else /* _WIN32 */
92 
93 #ifndef __PRI64_PREFIX
94 # if __WORDSIZE == 64
95 # define __PRI64_PREFIX "l"
96 # else
97 # define __PRI64_PREFIX "ll"
98 # endif
99 #endif
100 
101 #ifndef PRIdS
102 # define PRIdS "zd"
103 #endif
104 
105 #ifndef PRIu64
106 # define PRIu64 __PRI64_PREFIX "u"
107 #endif
108 
109 #ifndef PRIuMAX
110 # define PRIuMAX __PRI64_PREFIX "u"
111 #endif
112 
113 #ifndef PRIxMAX
114 #define PRIxMAX __PRI64_PREFIX "x"
115 #endif
116 
117 #ifndef PRIXMAX
118 #define PRIXMAX __PRI64_PREFIX "X"
119 #endif
120 
121 #endif /* _WIN32 */
122 
124 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
125 
127 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
128 
130 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
131 
133 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
134 
136 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
137 
150 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
151 
155 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
156 
157 #endif /* CMOCKA_PRIVATE_H_ */