Version 3.0.23.01.25
[clinfo] / src / ms_support.h
1 /* Missing functions and other misc stuff to support
2  * the horrible MS C compiler
3  *
4  * TODO could be improved by version-checking for C99 support
5  */
6
7 #ifndef MS_SUPPORT
8 #define MS_SUPPORT
9
10 // disable warning about unsafe strncpy vs strncpy_s usage
11 #pragma warning(disable : 4996)
12 // disable warning about constant conditional expressions
13 #pragma warning(disable : 4127)
14 // disable warning about non-constant aggregate initializer
15 #pragma warning(disable : 4204)
16
17 // disable warning about global shadowing
18 #pragma warning(disable : 4459)
19 // disable warning about parameter shadowing
20 #pragma warning(disable : 4457)
21
22 // Suppress warning about unused parameters. The macro definition
23 // _should_ work, but it doesn't on VS2012 (cl 17), may be a version thing
24 #define UNUSED(x) x __pragma(warning(suppress: 4100))
25 // TODO FIXME remove full-blown warning removal where not needed
26 #pragma warning(disable: 4100)
27
28 // No inline in MS C
29 #define inline __inline
30
31 // No snprintf in MS C, copy over implementation taken from
32 // stackoverflow
33
34 #include <stdarg.h>
35 #include <stdio.h>
36
37 inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
38 {
39     int count = -1;
40
41     if (size != 0)
42         count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
43     if (count == -1)
44         count = _vscprintf(format, ap);
45
46     return count;
47 }
48
49 inline int c99_snprintf(char* str, size_t size, const char* format, ...)
50 {
51     int count;
52     va_list ap;
53
54     va_start(ap, format);
55     count = c99_vsnprintf(str, size, format, ap);
56     va_end(ap);
57
58     return count;
59 }
60
61 #define snprintf c99_snprintf
62
63 // And no __func__ either
64
65 #define __func__ __FUNCTION__
66
67 #endif