fbxstdcompliant.h 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /****************************************************************************************
  2. Copyright (C) 2015 Autodesk, Inc.
  3. All rights reserved.
  4. Use of this software is subject to the terms of the Autodesk license agreement
  5. provided at the time of installation or download, or which otherwise accompanies
  6. this software in either electronic or hard copy form.
  7. ****************************************************************************************/
  8. /** \file fbxstdcompliant.h
  9. * Macros to properly support the CRT secure functions. */
  10. #ifndef _FBXSDK_CORE_ARCH_STDCOMPLIANT_H_
  11. #define _FBXSDK_CORE_ARCH_STDCOMPLIANT_H_
  12. #include <fbxsdk/fbxsdk_def.h>
  13. #include <fbxsdk/fbxsdk_nsbegin.h>
  14. #if defined(FBXSDK_ENV_WIN)
  15. #define FBXSDK_printf printf_s
  16. #define FBXSDK_fprintf fprintf_s
  17. inline int FBXSDK_sprintf(char* dst, size_t dstsize, const char* format, ...){ va_list vl; va_start(vl, format); int ret = vsprintf_s(dst, dstsize, format, vl); va_end(vl); return ret; }
  18. inline int FBXSDK_snprintf(char* dst, size_t dstsize, const char* format, ...){ va_list vl; va_start(vl, format); int ret = vsnprintf_s(dst, dstsize, _TRUNCATE, format, vl); va_end(vl); return ret; }
  19. inline int FBXSDK_vsprintf(char* dst, size_t dstsize, const char* format, va_list vl){ return vsprintf_s(dst, dstsize, format, vl); }
  20. inline int FBXSDK_vsnprintf(char* dst, size_t dstsize, const char* format, va_list vl){ return vsnprintf_s(dst, dstsize, _TRUNCATE, format, vl); }
  21. #define FBXSDK_stricmp(dst, src) _stricmp(dst, src)
  22. #define FBXSDK_strnicmp(dst, src, count) _strnicmp(dst, src, count)
  23. #define FBXSDK_strcpy(dst, size, src) strcpy_s(dst, size, src)
  24. #define FBXSDK_strncpy(dst, size, src, count) strncpy_s(dst, size, src, count)
  25. #define FBXSDK_strcat(dst, size, src) strcat_s(dst, size, src)
  26. #define FBXSDK_strtok(str, delim, ctx) strtok_s(str, delim, ctx)
  27. #define FBXSDK_wcscpy(dst, size, src) wcscpy_s(dst, size, src)
  28. #define FBXSDK_wcscat(dst, size, src) wcscat_s(dst, size, src)
  29. #if !defined(FBXSDK_ENV_WINSTORE)
  30. #define FBXSDK_getpid _getpid
  31. #define FBXSDK_getcwd _getcwd
  32. #else
  33. inline int FBXSDK_getpid(){ return 0; }
  34. inline char* FBXSDK_getcwd(char*,int){ return NULL; }
  35. #endif
  36. #define FBXSDK_localtime(ptm, time) { struct tm tms; ptm = &tms; localtime_s(ptm, time); }
  37. #define FBXSDK_gmtime(ptm, time) { struct tm tms; ptm = &tms; gmtime_s(ptm, time); }
  38. #define FBXSDK_fopen(fp, name, mode) fopen_s(&fp, name, mode)
  39. #elif defined(FBXSDK_ENV_MAC) || defined(FBXSDK_ENV_LINUX)
  40. #define FBXSDK_printf printf
  41. #define FBXSDK_fprintf fprintf
  42. inline int FBXSDK_sprintf(char* dst, size_t dstsize, const char* format, ...){ va_list vl; va_start(vl, format); int ret = vsprintf(dst, format, vl); va_end(vl); return ret; }
  43. inline int FBXSDK_snprintf(char* dst, size_t dstsize, const char* format, ...){ va_list vl; va_start(vl, format); int ret = vsnprintf(dst, dstsize, format, vl); va_end(vl); return ret; }
  44. inline int FBXSDK_vsprintf(char* dst, size_t dstsize, const char* format, va_list vl){ return vsprintf(dst, format, vl); }
  45. inline int FBXSDK_vsnprintf(char* dst, size_t dstsize, const char* format, va_list vl){ return vsnprintf(dst, dstsize, format, vl); }
  46. #define FBXSDK_stricmp(dst, src) stricmp(dst, src)
  47. #define FBXSDK_strnicmp(dst, src, count) strnicmp(dst, src, count)
  48. #define FBXSDK_strcpy(dst, size, src) strcpy(dst, src)
  49. #define FBXSDK_strncpy(dst, size, src, count) strncpy(dst, src, count)
  50. #define FBXSDK_strcat(dst, size, src) strcat(dst, src)
  51. #define FBXSDK_strtok(str, delim, ctx) strtok(str, delim)
  52. #define FBXSDK_wcscpy(dst, size, src) wcscpy(dst, src)
  53. #define FBXSDK_wcscat(dst, size, src) wcscat_s(dst, src)
  54. #define FBXSDK_getpid getpid
  55. #define FBXSDK_getcwd getcwd
  56. #define FBXSDK_localtime(tm, time) tm=localtime(time)
  57. #define FBXSDK_gmtime(tm, time) tm=gmtime(time)
  58. #define FBXSDK_fopen(fp, name, mode) fp=fopen(name, mode)
  59. #else
  60. #error Unsupported platform!
  61. #endif
  62. #define FBXSDK_strdup FbxStrDup
  63. //The scanf family functions cannot easily be used in both secure and non-secure versions because
  64. //Microsoft's secure version expects the size of the string/char* arguments following their address.
  65. //On Unix machines the scanf family functions do not have this behavior and trying to use the same
  66. //calls would result in compiler errors because the arguments would not match the format string.
  67. //Using the following macros in the code will simply desable the warning at compile time.
  68. #if defined(FBXSDK_COMPILER_MSC) && (_MSC_VER >= 1300)
  69. #define FBXSDK_CRT_SECURE_NO_WARNING_BEGIN\
  70. {\
  71. __pragma(warning(push))\
  72. __pragma(warning(disable : 4996))\
  73. }
  74. #define FBXSDK_CRT_SECURE_NO_WARNING_END\
  75. {\
  76. __pragma(warning(pop))\
  77. }
  78. #else
  79. #define FBXSDK_CRT_SECURE_NO_WARNING_BEGIN
  80. #define FBXSDK_CRT_SECURE_NO_WARNING_END
  81. #endif
  82. #include <fbxsdk/fbxsdk_nsend.h>
  83. #endif /* _FBXSDK_CORE_ARCH_STDCOMPLIANT_H_ */