CCStdC-win32.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CC_STD_C_H__
  22. #define __CC_STD_C_H__
  23. #include "platform/CCPlatformConfig.h"
  24. #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
  25. #include <BaseTsd.h>
  26. #ifndef __SSIZE_T
  27. #define __SSIZE_T
  28. typedef SSIZE_T ssize_t;
  29. #endif // __SSIZE_T
  30. #include "platform/CCPlatformMacros.h"
  31. #include <float.h>
  32. // for math.h on win32 platform
  33. #ifndef __MINGW32__
  34. #if !defined(_USE_MATH_DEFINES)
  35. #define _USE_MATH_DEFINES // make M_PI can be use
  36. #endif
  37. #if _MSC_VER < 1800
  38. #if !defined(isnan)
  39. #define isnan _isnan
  40. #endif
  41. #endif
  42. #if _MSC_VER < 1900
  43. #ifndef snprintf
  44. #define snprintf _snprintf
  45. #endif
  46. #endif
  47. #endif // __MINGW32__
  48. #include <math.h>
  49. #include <string.h>
  50. #include <stdarg.h>
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <time.h>
  54. #ifndef M_PI
  55. #define M_PI 3.14159265358
  56. #endif
  57. #ifndef M_PI_2
  58. #define M_PI_2 1.57079632679
  59. #endif
  60. // for MIN MAX and sys/time.h on win32 platform
  61. #ifdef __MINGW32__
  62. #include <sys/time.h>
  63. #endif // __MINGW32__
  64. #ifndef MIN
  65. #define MIN(x,y) (((x) > (y)) ? (y) : (x))
  66. #endif // MIN
  67. #ifndef MAX
  68. #define MAX(x,y) (((x) < (y)) ? (y) : (x))
  69. #endif // MAX
  70. #if _MSC_VER >= 1600 || defined(__MINGW32__)
  71. #include <stdint.h>
  72. #else
  73. #include "platform/win32/compat/stdint.h"
  74. #endif
  75. #define _WINSOCKAPI_
  76. #ifndef NOMINMAX
  77. #define NOMINMAX
  78. #endif
  79. // Structure timeval has define in winsock.h, include windows.h for it.
  80. #include <Windows.h>
  81. #ifndef __MINGW32__
  82. #include <WinSock2.h>
  83. NS_CC_BEGIN
  84. struct timezone
  85. {
  86. int tz_minuteswest;
  87. int tz_dsttime;
  88. };
  89. int CC_DLL gettimeofday(struct timeval *, struct timezone *);
  90. NS_CC_END
  91. #else
  92. #undef _WINSOCKAPI_
  93. #include <winsock2.h>
  94. // Conflicted with math.h isnan
  95. #include <cmath>
  96. using std::isnan;
  97. inline int vsnprintf_s(char *buffer, size_t sizeOfBuffer, size_t count,
  98. const char *format, va_list argptr) {
  99. return vsnprintf(buffer, sizeOfBuffer, format, argptr);
  100. }
  101. #ifndef __clang__
  102. inline errno_t strcpy_s(char *strDestination, size_t numberOfElements,
  103. const char *strSource) {
  104. strcpy(strDestination, strSource);
  105. return 0;
  106. }
  107. #endif
  108. #endif // __MINGW32__
  109. // Conflicted with cocos2d::MessageBox, so we need to undef it.
  110. #ifdef MessageBox
  111. #undef MessageBox
  112. #endif
  113. // Conflicted with ParticleSystem::PositionType::RELATIVE, so we need to undef it.
  114. #ifdef RELATIVE
  115. #undef RELATIVE
  116. #endif
  117. // Conflicted with CCBReader::SizeType::RELATIVE and CCBReader::ScaleType::RELATIVE, so we need to undef it.
  118. #ifdef ABSOLUTE
  119. #undef ABSOLUTE
  120. #endif
  121. // Conflicted with HttpRequest::Type::DELETE, so we need to undef it.
  122. #ifdef DELETE
  123. #undef DELETE
  124. #endif
  125. #undef min
  126. #undef max
  127. #endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
  128. #endif // __CC_STD_C_H__