[Spice-devel] [vdagent-win PATCH V3 08/11] Fix building with Visual Studio (snprintf)

Uri Lublin uril at redhat.com
Tue Dec 30 08:20:54 PST 2014


This commit is an addition to 4b9e9b1d28ea7eaec44ff73e2f91c4064986b12a

Building with Visual Studio breaks as snprintf is not implemented:
  vdagent\file_xfer.cpp(198) : error C3861: 'snprintf': identifier not found

Replace it with sprintf_s for Visual Studio.

Trying to use sprintf_s for both Visual Studio and mingw
failed for mingw64 (build succeeds but runtime error appears).
---
 common/vdcommon.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/common/vdcommon.h b/common/vdcommon.h
index 74496f1..568e3ba 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -68,6 +68,10 @@ typedef CRITICAL_SECTION mutex_t;
 #endif
 #endif /* OLDMSVCRT */
 
+#ifdef _MSC_VER // compiling with Visual Studio
+#define snprintf         sprintf_s
+#endif
+
 enum SystemVersion {
     SYS_VER_UNSUPPORTED,
     SYS_VER_WIN_XP_CLASS, // also Server 2003/R2
-- 
1.7.1



More information about the Spice-devel mailing list