1 /* Copyright (C) 2010-2018 The RetroArch team 2 * 3 * --------------------------------------------------------------------------------------- 4 * The following license statement only applies to this file (msvc.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 <stdlib.h> 36 #ifndef snprintf 37 #define snprintf c99_snprintf_retro__ 38 #endif 39 40 int c99_snprintf_retro__(char *outBuf, size_t size, const char *format, ...); 41 #endif 42 43 /* Pre-MSVC 2008 compilers don't implement vsnprintf in a cross-platform manner? Not sure about this one. */ 44 #if _MSC_VER < 1500 45 #include <stdio.h> 46 #include <stdarg.h> 47 #include <stdlib.h> 48 #ifndef vsnprintf 49 #define vsnprintf c99_vsnprintf_retro__ 50 #endif 51 int c99_vsnprintf_retro__(char *outBuf, size_t size, const char *format, va_list ap); 52 #endif 53 54 #ifdef __cplusplus 55 } 56 #endif 57 58 #undef UNICODE /* Do not bother with UNICODE at this time. */ 59 #include <direct.h> 60 #include <stddef.h> 61 62 #define _USE_MATH_DEFINES 63 #include <math.h> 64 65 /* Python headers defines ssize_t and sets HAVE_SSIZE_T. 66 * Cannot duplicate these efforts. 67 */ 68 #ifndef HAVE_SSIZE_T 69 #if defined(_WIN64) 70 typedef __int64 ssize_t; 71 #elif defined(_WIN32) 72 typedef int ssize_t; 73 #endif 74 #endif 75 76 #define mkdir(dirname, unused) _mkdir(dirname) 77 #define strtoull _strtoui64 78 #undef strcasecmp 79 #define strcasecmp _stricmp 80 #undef strncasecmp 81 #define strncasecmp _strnicmp 82 83 /* Disable some of the annoying warnings. */ 84 #pragma warning(disable : 4800) 85 #pragma warning(disable : 4805) 86 #pragma warning(disable : 4244) 87 #pragma warning(disable : 4305) 88 #pragma warning(disable : 4146) 89 #pragma warning(disable : 4267) 90 #pragma warning(disable : 4723) 91 #pragma warning(disable : 4996) 92 93 /* roundf and va_copy is available since MSVC 2013 */ 94 #if _MSC_VER < 1800 95 #define roundf(in) (in >= 0.0f ? floorf(in + 0.5f) : ceilf(in - 0.5f)) 96 #define va_copy(x, y) ((x) = (y)) 97 #endif 98 99 #if _MSC_VER <= 1310 100 #ifndef __cplusplus 101 /* VC6 math.h doesn't define some functions when in C mode. 102 * Trying to define a prototype gives "undefined reference". 103 * But providing an implementation then gives "function already has body". 104 * So the equivalent of the implementations from math.h are used as 105 * defines here instead, and it seems to work. 106 */ 107 #define cosf(x) ((float)cos((double)x)) 108 #define powf(x, y) ((float)pow((double)x, (double)y)) 109 #define sinf(x) ((float)sin((double)x)) 110 #define ceilf(x) ((float)ceil((double)x)) 111 #define floorf(x) ((float)floor((double)x)) 112 #define sqrtf(x) ((float)sqrt((double)x)) 113 #define fabsf(x) ((float)fabs((double)(x))) 114 #endif 115 116 #ifndef _strtoui64 117 #define _strtoui64(x, y, z) (_atoi64(x)) 118 #endif 119 120 #endif 121 122 #ifndef PATH_MAX 123 #define PATH_MAX _MAX_PATH 124 #endif 125 126 #ifndef SIZE_MAX 127 #define SIZE_MAX _UI32_MAX 128 #endif 129 130 #endif 131 #endif 132