17#ifndef CMOCKA_PRIVATE_H_
18#define CMOCKA_PRIVATE_H_
24#ifndef CMOCKA_NO_STANDARD_INCLUDES
36# define inline __inline
39# define va_copy(dest, src) (dest = src)
42# define strcasecmp _stricmp
43# define strncasecmp _strnicmp
44# define strtok_r strtok_s
45# define strdup _strdup
47# if defined(HAVE__SNPRINTF_S)
49# define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
51# if defined(HAVE__SNPRINTF)
53# define snprintf _snprintf
55# if !defined(HAVE_SNPRINTF)
56# error "no snprintf compatible function found"
61# if defined(HAVE__VSNPRINTF_S)
63# define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
65# if defined(HAVE__VSNPRINTF)
67# define vsnprintf _vsnprintf
69# if !defined(HAVE_VSNPRINTF)
70# error "No vsnprintf compatible function found"
85# define PRIuMAX PRIu64
98#define PATH_MAX MAX_PATH
106#ifndef __PRI64_PREFIX
108# define __PRI64_PREFIX "l"
110# define __PRI64_PREFIX "ll"
119# define PRIu64 __PRI64_PREFIX "u"
123# define PRIuMAX __PRI64_PREFIX "u"
127#define PRIxMAX __PRI64_PREFIX "x"
131#define PRIXMAX __PRI64_PREFIX "X"
137#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
140#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
143#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
146#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
149#define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
163#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
168#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
173# if defined(__GNUC__) || defined(__clang__)
174# define INFINITY __builtin_inff()
176# define INFINITY ((float)(1e+300 * 1e+300))
181# if defined(__GNUC__) || defined(__clang__)
182# define NAN __builtin_nanf("")
184# define NAN ((float)(INFINITY * 0.0f))
189static inline int cmocka_isnan(
double x) {
190 union {
double d; uint64_t i; } u;
193 return ((u.i & 0x7FF0000000000000ULL) == 0x7FF0000000000000ULL) &&
194 ((u.i & 0x000FFFFFFFFFFFFFULL) != 0);
196# define isnan(x) cmocka_isnan(x)
200static inline int cmocka_isinf(
double x) {
201 union {
double d; uint64_t i; } u;
204 return ((u.i & 0x7FF0000000000000ULL) == 0x7FF0000000000000ULL) &&
205 ((u.i & 0x000FFFFFFFFFFFFFULL) == 0);
207# define isinf(x) cmocka_isinf(x)