[Portability] Implemented snprintf() function to support old compilers



git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3290 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/common-config.win.h b/common/common-config.win.h
index e68d372..b984fb4 100644
--- a/common/common-config.win.h
+++ b/common/common-config.win.h
@@ -2,3 +2,6 @@
 
 #define HAVE_VSNPRINTF 1
 #define vsnprintf _vsnprintf
+
+#define HAVE_SNPRINTF 1
+#define snprintf _snprintf
diff --git a/common/configure.ac b/common/configure.ac
index a9fe241..25aa5f0 100644
--- a/common/configure.ac
+++ b/common/configure.ac
@@ -78,7 +78,7 @@
 AM_CONDITIONAL([INCLUDED_JPEG], [ test "x$INCLUDED_JPEG" = xyes ])
 AC_CONFIG_SUBDIRS([jpeg])
 
-AC_CHECK_FUNCS_ONCE([vsnprintf strcasecmp strncasecmp getaddrinfo])
+AC_CHECK_FUNCS_ONCE([vsnprintf snprintf strcasecmp strncasecmp getaddrinfo])
 
 AC_CHECK_TYPES([socklen_t],
 	[AC_DEFINE([VNC_SOCKLEN_T], [socklen_t], [Use correct size])],
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx
index a45e535..4a37d01 100644
--- a/common/network/TcpSocket.cxx
+++ b/common/network/TcpSocket.cxx
@@ -24,7 +24,6 @@
 //#include <io.h>
 #include <winsock2.h>
 #define errorNumber WSAGetLastError()
-#define snprintf _snprintf
 #ifndef VNC_SOCKLEN_T
 #define VNC_SOCKLEN_T int
 #endif
diff --git a/common/os/print.c b/common/os/print.c
index f24717f..0f26de3 100644
--- a/common/os/print.c
+++ b/common/os/print.c
@@ -89,3 +89,16 @@
 }
 #endif /* HAVE_VSNPRINTF */
 
+#ifndef HAVE_SNPRINTF
+int tight_snprintf(char *str, size_t n, const char *format, ...) {
+	va_list ap;
+	int written;
+
+	va_start(ap, format);
+	written = vsnprintf(str, n, format, ap);
+	va_end(ap);
+
+	return written;
+}
+#endif /* HAVE_SNPRINTF */
+
diff --git a/common/os/print.h b/common/os/print.h
index 47893ad..523f3a1 100644
--- a/common/os/print.h
+++ b/common/os/print.h
@@ -48,6 +48,12 @@
 #define vsnprintf tight_vsnprintf
 #endif
 
+#ifndef HAVE_SNPRINTF
+/* Inherits tight_vsnprintf limitations if vsnprintf is not present */
+int tight_snprintf(char *str, size_t n, const char *format, ...);
+#define snprintf tight_snprintf
+#endif
+
 #ifdef __cplusplus
 };
 #endif