msvc.h 4.1 KB

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