Debian Codegraph @

libretro-common/include/compat/msvc.h

raw symbols SCIP
1 /* Copyright (C) 2010-2016 The RetroArch team
2 *
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (msvc_compat.h).
5 * ---------------------------------------------------------------------------------------
6 *
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 #ifndef __LIBRETRO_SDK_COMPAT_MSVC_H
24 #define __LIBRETRO_SDK_COMPAT_MSVC_H
25
26 #ifdef _MSC_VER
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /* Pre-MSVC 2015 compilers don't implement snprintf in a cross-platform manner. */
33 #if _MSC_VER < 1900
34 #include <stdio.h>
35 #include <stdarg.h>
36 #define snprintf c99_snprintf
37 #define vsnprintf c99_vsnprintf
38
39 _inline int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
40 {
41 int count = -1;
42
43 if (size != 0)
44 count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
45 if (count == -1)
46 count = _vscprintf(format, ap);
47
48 return count;
49 }
50
51 _inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
52 {
53 int count;
54 va_list ap;
55
56 va_start(ap, format);
57 count = c99_vsnprintf(outBuf, size, format, ap);
58 va_end(ap);
59
60 return count;
61 }
62 #endif
63
64 #ifdef __cplusplus
65 }
66 #endif
67
68 #undef UNICODE /* Do not bother with UNICODE at this time. */
69 #include <direct.h>
70 #include <stddef.h>
71 #include <math.h>
72
73 /* Python headers defines ssize_t and sets HAVE_SSIZE_T.
74 * Cannot duplicate these efforts.
75 */
76 #ifndef HAVE_SSIZE_T
77 #if defined(_WIN64)
78 typedef __int64 ssize_t;
79 #elif defined(_WIN32)
80 typedef int ssize_t;
81 #endif
82 #endif
83
84 #define mkdir(dirname, unused) _mkdir(dirname)
85 #define strtoull _strtoui64
86 #undef strcasecmp
87 #define strcasecmp _stricmp
88 #undef strncasecmp
89 #define strncasecmp _strnicmp
90
91 /* Disable some of the annoying warnings. */
92 #pragma warning(disable : 4800)
93 #pragma warning(disable : 4805)
94 #pragma warning(disable : 4244)
95 #pragma warning(disable : 4305)
96 #pragma warning(disable : 4146)
97 #pragma warning(disable : 4267)
98 #pragma warning(disable : 4723)
99 #pragma warning(disable : 4996)
100
101 /* roundf is available since MSVC 2013 */
102 #if _MSC_VER < 1800
103 #define roundf(in) (in >= 0.0f ? floorf(in + 0.5f) : ceilf(in - 0.5f))
104 #endif
105
106 #ifndef PATH_MAX
107 #define PATH_MAX _MAX_PATH
108 #endif
109
110 #ifndef SIZE_MAX
111 #define SIZE_MAX _UI32_MAX
112 #endif
113
114 #endif
115 #endif
116