summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Tkac <atkac@redhat.com>2008-12-03 14:18:19 +0000
committerAdam Tkac <atkac@redhat.com>2008-12-03 14:18:19 +0000
commit3422fbd158632894ae203f6d7fc2cddfbcbf7a73 (patch)
tree8f5f9ea0aeee2bd88bfbc74a1b592785cefa95d1
parent241e9009710f205fb95273a9bed9684285a2ef0d (diff)
downloadtigervnc-3422fbd158632894ae203f6d7fc2cddfbcbf7a73.tar.gz
tigervnc-3422fbd158632894ae203f6d7fc2cddfbcbf7a73.zip
[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
-rw-r--r--common/common-config.win.h3
-rw-r--r--common/configure.ac2
-rw-r--r--common/network/TcpSocket.cxx1
-rw-r--r--common/os/print.c13
-rw-r--r--common/os/print.h6
5 files changed, 23 insertions, 2 deletions
diff --git a/common/common-config.win.h b/common/common-config.win.h
index e68d3724..b984fb40 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 a9fe241a..25aa5f09 100644
--- a/common/configure.ac
+++ b/common/configure.ac
@@ -78,7 +78,7 @@ AC_ARG_WITH([included-jpeg],
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 a45e535b..4a37d01c 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 f24717fb..0f26de36 100644
--- a/common/os/print.c
+++ b/common/os/print.c
@@ -89,3 +89,16 @@ int tight_vsnprintf(char *str, size_t n, const char *format, va_list ap) {
}
#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 47893adf..523f3a1f 100644
--- a/common/os/print.h
+++ b/common/os/print.h
@@ -48,6 +48,12 @@ int tight_vsnprintf(char *str, size_t n, const char *format, va_list ap);
#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