Commits

Don Williamson committed 8b555e9

Resolved the snprintf conflict for Visual Studio correctly: define to use _snprintf instead of requiring the user to provide an implementation themselves.

Comments (0)

Files changed (3)

src/clReflectTest/Main.cpp

 #include <errno.h>
 
 
-#ifdef _MSC_VER
-extern "C" int snprintf(char* dest, unsigned int n, const char* fmt, ...)
-{
-	// Unfortunately snprintf is not a standardised function and MSVC has its own "safe" version
-	va_list args;
-	va_start(args, fmt);
-	int count = vsnprintf_s(dest, n, _TRUNCATE, fmt, args);
-	va_end(args);
-
-	// This seems to be he only valid way of detecting truncation
-	if (errno == 0 && count == -1)
-		return n - 1;
-
-	return count;
-}
-#endif
-
-
 class StdFile : public clcpp::IFile
 {
 public:

src/clReflectUtil/Platform.cpp

 #include "Platform.h"
 
 
-// check for operating systems
-#if defined(_WINDOWS) || defined(_WIN32)
-
-	#define CLUTL_PLATFORM_WINDOWS
-
-#elif defined(__linux__) || defined(__APPLE__)
-
-	#define CLUTL_PLATFORM_POSIX
-
-#endif
-
-
 #if defined(CLUTL_PLATFORM_WINDOWS)
 	// Windows-specific module loading and inspection functions
 	typedef int (__stdcall *FunctionPtr)();

src/clReflectUtil/Platform.h

 // All dependencies must come through here without this header file invoking platform-specific header files.
 
 
+// check for operating systems
+#if defined(_WINDOWS) || defined(_WIN32)
+
+	#define CLUTL_PLATFORM_WINDOWS
+
+#elif defined(__linux__) || defined(__APPLE__)
+
+	#define CLUTL_PLATFORM_POSIX
+
+#endif
+
+
 // Standard C library function, convert string to double-precision number
 // http://pubs.opengroup.org/onlinepubs/007904975/functions/strtod.html
 extern "C" double strtod(const char* s00, char** se);
 
 
 // Non-standard, writes at most n bytes to dest with printf formatting
-// On Win32/MSVC, this usually maps to _snprintf_s
-extern "C" int snprintf(char* dest, unsigned int n, const char* fmt, ...);
+#if defined(CLUTL_PLATFORM_WINDOWS)
+	extern "C" int _snprintf(char* dest, unsigned int n, const char* fmt, ...);
+	#define snprintf _snprintf
+#else
+	extern "C" int snprintf(char* dest, unsigned int n, const char* fmt, ...);
+#endif
 
 
 // Share library (DLL/SO) implementations