fbxstdcompliant.h

Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2012 Autodesk, Inc.
00004    All rights reserved.
00005  
00006    Use of this software is subject to the terms of the Autodesk license agreement
00007    provided at the time of installation or download, or which otherwise accompanies
00008    this software in either electronic or hard copy form.
00009  
00010 ****************************************************************************************/
00011 
00016 #ifndef _FBXSDK_CORE_ARCH_STDCOMPLIANT_H_
00017 #define _FBXSDK_CORE_ARCH_STDCOMPLIANT_H_
00018 
00019 #include <fbxsdk/fbxsdk_def.h>
00020 
00021 #include <fbxsdk/fbxsdk_nsbegin.h>
00022 
00023 #if defined(FORCE_UNSECURE_CALLS) || defined (FBXSDK_ENV_MAC) || defined (FBXSDK_ENV_LINUX)
00024     inline int FBXSDK_sprintf(char* buffer, size_t dummy, const char* format, ...) 
00025     { 
00026         va_list vl;
00027         va_start( vl, format);
00028         
00029         int ret = vsprintf(buffer, format, vl); 
00030         va_end( vl );
00031         return ret;
00032     }
00033     inline int FBXSDK_snprintf(char* buffer, size_t dummy, size_t count, const char* format, ...) 
00034     { 
00035         va_list vl;
00036         va_start( vl, format);
00037         
00038         #if defined (FBXSDK_ENV_WIN)
00039             int ret = _vsnprintf(buffer, count, format, vl); 
00040         #else
00041             int ret = vsnprintf(buffer, count, format, vl); 
00042         #endif
00043         va_end( vl );
00044         return ret;
00045     }
00046     inline int FBXSDK_vsprintf(char* buffer, size_t dummy, const char* format, va_list vl) 
00047     { 
00048         int ret = vsprintf(buffer, format, vl); 
00049         return ret;
00050     }
00051     inline int FBXSDK_vsnprintf(char* buffer, size_t dummy, size_t count, const char* format, va_list vl) 
00052     { 
00053         int ret = vsnprintf(buffer, count, format, vl); 
00054         return ret;
00055     }
00056 
00057     #define FBXSDK_stricmp(dst, src)                stricmp(dst, src)
00058     #define FBXSDK_strnicmp(dst,src,count)          strnicmp(dst, src, count)
00059     #define FBXSDK_strcpy(dst,dstSize,src)          strcpy(dst, src)
00060     #define FBXSDK_strncpy(dst,dstSize,src,count)   strncpy(dst, src, count)
00061     #define FBXSDK_strcat(dst,dstSize,src)          strcat(dst, src)
00062     #define FBXSDK_strtok(str,delim,context)        strtok(str,delim)
00063     #define FBXSDK_strdup                           strdup
00064 
00065     #define FBXSDK_wcscpy(dst,dstSize,src)          wcscpy(dst, src)
00066     #define FBXSDK_wcscat(dst,dstSize,src)          wcscat_s(dst,src)
00067 
00068     #define FBXSDK_getpid                           getpid  
00069 
00070     #define FBXSDK_fopen(fp, name, mode)            fp=fopen(name, mode)
00071     #define FBXSDK_fclose                           fclose
00072 
00073     #define FBXSDK_getcwd                           getcwd
00074 
00075     #define FBXSDK_printf                           printf
00076     #define FBXSDK_fprintf                          fprintf
00077 
00078     #define FBXSDK_localtime(tm,time)               tm=localtime(time)
00079     #define FBXSDK_gmtime(tm, time)                 tm=gmtime(time)
00080 
00081 
00082 #elif defined (FBXSDK_ENV_WIN)
00083     // Microsoft secure calls
00084     #define FBXSDK_stricmp(dst, src)                _stricmp(dst, src)
00085     #define FBXSDK_strnicmp(dst,src,count)          _strnicmp(dst, src, count)
00086     #define FBXSDK_strcpy(dst,dstSize,src)          strcpy_s(dst, dstSize, src)
00087     #define FBXSDK_strncpy(dst,dstSize,src,count)   strncpy_s(dst, dstSize, src, count)
00088     #define FBXSDK_strcat(dst,dstSize,src)          strcat_s(dst, dstSize, src)
00089     #define FBXSDK_strtok(str,delim,context)        strtok_s(str,delim,context)
00090     #define FBXSDK_strdup                           _strdup
00091 
00092     #define FBXSDK_wcscpy(dst,dstSize,src)          wcscpy_s(dst, dstSize, src)
00093     #define FBXSDK_wcscat(dst,dstSize,src)          wcscat_s(dst,dstSize,src)
00094 
00095     #define FBXSDK_getpid                           _getpid
00096 
00097     #define FBXSDK_fopen(fp, name, mode)            fopen_s(&fp, name, mode)
00098     #define FBXSDK_fclose                           fclose
00099 
00100     #define FBXSDK_getcwd                           _getcwd
00101 
00102     #define FBXSDK_printf                           printf_s
00103     #define FBXSDK_fprintf                          fprintf_s
00104     #define FBXSDK_sprintf                          sprintf_s
00105     #define FBXSDK_vsprintf                         vsprintf_s
00106     #define FBXSDK_vsnprintf                        vsnprintf_s
00107     #define FBXSDK_snprintf                         _snprintf_s
00108 
00109     #define FBXSDK_localtime(ptm,time)              { struct tm tms; ptm = &tms; localtime_s(ptm, time); }
00110     #define FBXSDK_gmtime(ptm, time)                { struct tm tms; ptm = &tms; gmtime_s(ptm, time); }
00111 #else
00112     // Unknown platform
00113     #error Unsupported platform!
00114 #endif
00115 
00116 // The scanf family functions cannot easily be used in both secure and non-secure versions because
00117 // Microsoft's secure version expects the size of the string/char* arguments following their address.
00118 // On Unix machines the scanf family functions do not have this behavior and trying to use the same calls
00119 // would result in compiler errors because the arguments would not match the format string.
00120 //
00121 // Using the following macros in the code will simply desable the warning at compile time.
00122 //
00123 #if defined(FBXSDK_COMPILER_MSC) && _MSC_VER >= 1300
00124     #define FBXSDK_CRT_SECURE_NO_WARNING_BEGIN  \
00125     { \
00126         __pragma(warning(push)) \
00127         __pragma(warning( disable : 4996 )) \
00128     }
00129     
00130 #define FBXSDK_CRT_SECURE_NO_WARNING_END \
00131     { \
00132         __pragma(warning(pop)) \
00133     }
00134 #else
00135     #define FBXSDK_CRT_SECURE_NO_WARNING_BEGIN
00136     #define FBXSDK_CRT_SECURE_NO_WARNING_END
00137 #endif
00138 
00139 #include <fbxsdk/fbxsdk_nsend.h>
00140 
00141 #endif /* _FBXSDK_CORE_ARCH_STDCOMPLIANT_H_ */