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