[Scummvm-cvs-logs] scummvm-tools master -> d83efba499775f76a9664df7bdec948ed87f9d7c

Strangerke Strangerke at scummvm.org
Tue Jan 5 00:55:07 CET 2016


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm-tools' repo located at https://github.com/scummvm/scummvm-tools .

Summary:
d83efba499 TOOLS: Synchronize some code from Scummvm::Master in scummsys.h to make some tools compile using MSVC


Commit: d83efba499775f76a9664df7bdec948ed87f9d7c
    https://github.com/scummvm/scummvm-tools/commit/d83efba499775f76a9664df7bdec948ed87f9d7c
Author: Strangerke (strangerke at scummvm.org)
Date: 2016-01-05T00:48:48+01:00

Commit Message:
TOOLS: Synchronize some code from Scummvm::Master in scummsys.h to make some tools compile using MSVC

Changed paths:
    common/scummsys.h



diff --git a/common/scummsys.h b/common/scummsys.h
index 09524e4..aaa1013 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -33,7 +33,6 @@
 #endif
 
 #if defined(NONSTANDARD_PORT)
-
 	// Ports which need to perform #includes and #defines visible in
 	// virtually all the source of ScummVM should do so by providing a
 	// "portdefs.h" header file (and not by directly modifying this
@@ -42,11 +41,45 @@
 #else // defined(NONSTANDARD_PORT)
 
 	#if defined(WIN32)
-
 		#ifdef _MSC_VER
 		// vsnprintf is already defined in Visual Studio 2008
-		#if (_MSC_VER < 1500)
-			#define vsnprintf _vsnprintf
+		#if defined(_MSC_VER) && _MSC_VER <= 1800
+		// FIXME: The placement of the workaround functions for MSVC below
+		// require us to include stdio.h and stdarg.h for MSVC here. This
+		// is not exactly nice...
+		// We should think of a better way of doing this.
+		#include <stdio.h>
+		#include <stdarg.h>
+
+		// MSVC's vsnprintf is either non-existent (2003) or bugged since it
+		// does not always include a terminating NULL (2005+). To work around
+		// that we fix up the _vsnprintf included. Note that the return value
+		// will still not match C99's specs!
+		inline int vsnprintf_msvc(char *str, size_t size, const char *format, va_list args) {
+			// We do not pass size - 1 here, to ensure we would get the same
+			// return value as when we would use _vsnprintf directly, since
+			// for example Common::String::format relies on this.
+			int retValue = _vsnprintf(str, size, format, args);
+			str[size - 1] = 0;
+			return retValue;
+		}
+
+
+		#define vsnprintf vsnprintf_msvc
+
+		// Visual Studio does not include snprintf in its standard C library.
+		// Instead it includes a function called _snprintf with somewhat
+		// similar semantics. The minor difference is that the return value in
+		// case the formatted string exceeds the buffer size is different.
+		// A much more dangerous one is that _snprintf does not always include
+		// a terminating null (Whoops!). Instead we map to our fixed vsnprintf.
+		inline int snprintf(char *str, size_t size, const char *format, ...) {
+			va_list args;
+			va_start(args, format);
+			int len = vsnprintf(str, size, format, args);
+			va_end(args);
+			return len;
+		}
 		#endif
 		#endif
 






More information about the Scummvm-git-logs mailing list