From 3422fbd158632894ae203f6d7fc2cddfbcbf7a73 Mon Sep 17 00:00:00 2001 From: Adam Tkac Date: Wed, 3 Dec 2008 14:18:19 +0000 Subject: [PATCH] [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 --- common/common-config.win.h | 3 +++ common/configure.ac | 2 +- common/network/TcpSocket.cxx | 1 - common/os/print.c | 13 +++++++++++++ common/os/print.h | 6 ++++++ 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 #include #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 -- 2.39.5