diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2015-02-11 11:19:40 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2015-02-11 17:25:42 +0100 |
commit | 0aa331893f9ffeb40147b1448fee7467552d8c09 (patch) | |
tree | e28e47efbed46a9f7c41608c3c0345c477ebebc5 | |
parent | d06164e3cb97689413dc8ae5c965d59bf25f9b94 (diff) | |
download | cmocka-0aa331893f9ffeb40147b1448fee7467552d8c09.tar.gz cmocka-0aa331893f9ffeb40147b1448fee7467552d8c09.tar.bz2 cmocka-0aa331893f9ffeb40147b1448fee7467552d8c09.zip |
include: Add missing functions for Visual Studio.
Move the ugly stuff to cmocka_private.h.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | include/cmocka_private.h | 99 | ||||
-rw-r--r-- | src/cmocka.c | 64 |
2 files changed, 98 insertions, 65 deletions
diff --git a/include/cmocka_private.h b/include/cmocka_private.h index d633d64..4b71dfe 100644 --- a/include/cmocka_private.h +++ b/include/cmocka_private.h @@ -17,7 +17,104 @@ #ifndef CMOCKA_PRIVATE_H_ #define CMOCKA_PRIVATE_H_ -#include <cmocka.h> +#ifdef _WIN32 +#include <windows.h> + +# ifdef _MSC_VER + +# undef inline +# define inline __inline + +# define strcasecmp _stricmp +# define strncasecmp _strnicmp + +# if defined(HAVE__SNPRINTF_S) +# undef snprintf +# define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__) +# else /* HAVE__SNPRINTF_S */ +# if defined(HAVE__SNPRINTF) +# undef snprintf +# define snprintf _snprintf +# else /* HAVE__SNPRINTF */ +# if !defined(HAVE_SNPRINTF) +# error "no snprintf compatible function found" +# endif /* HAVE_SNPRINTF */ +# endif /* HAVE__SNPRINTF */ +# endif /* HAVE__SNPRINTF_S */ + +# if defined(HAVE__VSNPRINTF_S) +# undef vsnprintf +# define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v)) +# else /* HAVE__VSNPRINTF_S */ +# if defined(HAVE__VSNPRINTF) +# undef vsnprintf +# define vsnprintf _vsnprintf +# else +# if !defined(HAVE_VSNPRINTF) +# error "No vsnprintf compatible function found" +# endif /* HAVE_VSNPRINTF */ +# endif /* HAVE__VSNPRINTF */ +# endif /* HAVE__VSNPRINTF_S */ +# endif /* _MSC_VER */ + +/* + * Backwards compatibility with headers shipped with Visual Studio 2005 and + * earlier. + */ +WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID); + +#ifndef PRIdS +# define PRIdS "Id" +#endif + +#ifndef PRIu64 +# define PRIu64 "I64u" +#endif + +#ifndef PRIuMAX +# define PRIuMAX PRIu64 +#endif + +#ifndef PRIxMAX +#define PRIxMAX "I64x" +#endif + +#ifndef PRIXMAX +#define PRIXMAX "I64X" +#endif + +#else /* _WIN32 */ + +#ifndef __PRI64_PREFIX +# if __WORDSIZE == 64 +# define __PRI64_PREFIX "l" +# else +# define __PRI64_PREFIX "ll" +# endif +#endif + +#ifndef PRIdS +# define PRIdS "zd" +#endif + +#ifndef PRIu64 +# define PRIu64 __PRI64_PREFIX "u" +#endif + +#ifndef PRIuMAX +# define PRIuMAX __PRI64_PREFIX "u" +#endif + +#ifndef PRIxMAX +#define PRIxMAX __PRI64_PREFIX "x" +#endif + +#ifndef PRIXMAX +#define PRIXMAX __PRI64_PREFIX "X" +#endif + +#include <signal.h> +#endif /* _WIN32 */ /** Free memory space */ #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) diff --git a/src/cmocka.c b/src/cmocka.c index db77cb4..8cb31ea 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -35,70 +35,6 @@ #include <string.h> #include <time.h> -#ifdef _WIN32 -#include <windows.h> - -#define vsnprintf _vsnprintf - -/* - * Backwards compatibility with headers shipped with Visual Studio 2005 and - * earlier. - */ -WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID); - -#ifndef PRIdS -# define PRIdS "Id" -#endif - -#ifndef PRIu64 -# define PRIu64 "I64u" -#endif - -#ifndef PRIuMAX -# define PRIuMAX PRIu64 -#endif - -#ifndef PRIxMAX -#define PRIxMAX "I64x" -#endif - -#ifndef PRIXMAX -#define PRIXMAX "I64X" -#endif - -#else /* _WIN32 */ - -#ifndef __PRI64_PREFIX -# if __WORDSIZE == 64 -# define __PRI64_PREFIX "l" -# else -# define __PRI64_PREFIX "ll" -# endif -#endif - -#ifndef PRIdS -# define PRIdS "zd" -#endif - -#ifndef PRIu64 -# define PRIu64 __PRI64_PREFIX "u" -#endif - -#ifndef PRIuMAX -# define PRIuMAX __PRI64_PREFIX "u" -#endif - -#ifndef PRIxMAX -#define PRIxMAX __PRI64_PREFIX "x" -#endif - -#ifndef PRIXMAX -#define PRIXMAX __PRI64_PREFIX "X" -#endif - -#include <signal.h> -#endif /* _WIN32 */ - /* * This allows to add a platform specific header file. Some embedded platforms * sometimes miss certain types and definitions. |