cmocka  1.1.6
Unit testing library with mock support
Loading...
Searching...
No Matches
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#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <stdint.h>
25
26#ifdef _WIN32
27#include <windows.h>
28
29# ifdef _MSC_VER
30# include <stdio.h> /* _snprintf */
31# include <string.h> /* strtok_s */
32
33# undef inline
34# define inline __inline
35
36# ifndef va_copy
37# define va_copy(dest, src) (dest = src)
38# endif
39
40# define strcasecmp _stricmp
41# define strncasecmp _strnicmp
42# define strtok_r strtok_s
43
44# if defined(HAVE__SNPRINTF_S)
45# undef snprintf
46# define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
47# else /* HAVE__SNPRINTF_S */
48# if defined(HAVE__SNPRINTF)
49# undef snprintf
50# define snprintf _snprintf
51# else /* HAVE__SNPRINTF */
52# if !defined(HAVE_SNPRINTF)
53# error "no snprintf compatible function found"
54# endif /* HAVE_SNPRINTF */
55# endif /* HAVE__SNPRINTF */
56# endif /* HAVE__SNPRINTF_S */
57
58# if defined(HAVE__VSNPRINTF_S)
59# undef vsnprintf
60# define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
61# else /* HAVE__VSNPRINTF_S */
62# if defined(HAVE__VSNPRINTF)
63# undef vsnprintf
64# define vsnprintf _vsnprintf
65# else
66# if !defined(HAVE_VSNPRINTF)
67# error "No vsnprintf compatible function found"
68# endif /* HAVE_VSNPRINTF */
69# endif /* HAVE__VSNPRINTF */
70# endif /* HAVE__VSNPRINTF_S */
71# endif /* _MSC_VER */
72
73/*
74 * Backwards compatibility with headers shipped with Visual Studio 2005 and
75 * earlier.
76 */
77WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
78
79#ifndef PRIdS
80# define PRIdS "Id"
81#endif
82
83#ifndef PRIu64
84# define PRIu64 "I64u"
85#endif
86
87#ifndef PRIuMAX
88# define PRIuMAX PRIu64
89#endif
90
91#ifndef PRIxMAX
92#define PRIxMAX "I64x"
93#endif
94
95#ifndef PRIXMAX
96#define PRIXMAX "I64X"
97#endif
98
99#else /* _WIN32 */
100
101#ifndef __PRI64_PREFIX
102# if __WORDSIZE == 64
103# define __PRI64_PREFIX "l"
104# else
105# define __PRI64_PREFIX "ll"
106# endif
107#endif
108
109#ifndef PRIdS
110# define PRIdS "zd"
111#endif
112
113#ifndef PRIu64
114# define PRIu64 __PRI64_PREFIX "u"
115#endif
116
117#ifndef PRIuMAX
118# define PRIuMAX __PRI64_PREFIX "u"
119#endif
120
121#ifndef PRIxMAX
122#define PRIxMAX __PRI64_PREFIX "x"
123#endif
124
125#ifndef PRIXMAX
126#define PRIXMAX __PRI64_PREFIX "X"
127#endif
128
129#endif /* _WIN32 */
130
132#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
133
135#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
136
138#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
139
141#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
142
144#define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
145
158#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
159
163#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
164
165#endif /* CMOCKA_PRIVATE_H_ */