[PD-dev] snprintf vs. sprintf_s?
Russell Bryant
russell at russellbryant.net
Wed Jan 16 18:53:51 CET 2008
Martin Peach wrote:
> Probably. I did it like this in tcpclient.c, which compiles OK in
> pd-extended:
> #ifdef _MSC_VER
> #define snprintf sprintf_s
> #endif
>
> _MSC_VER is only defined for the microsoft compiler.
Yeah, that sounds like a better check than the custom MSW define.
If you wanted to take it a step further, it would be pretty trivial to add a
check for snprintf to the configure script. That way, when building Pd for .Net
or whatever (which I assume uses some other build system), the appropriate
HAVE_SNPRINTF define will not be present.
So, the source that needs this would look like this ... preferably in some
common non-installed header file so stuff like this can be put in a common place
and not replicated in lots of source files ...
#include "config.h"
#ifndef HAVE_SNPRINTF
/* Assume very silly non-standard windows version */
#define snprintf sprintf_s
#endif
Patch against current CVS HEAD for the configure script part would be ...
Index: configure.in
===================================================================
RCS file: /cvsroot/pure-data/pd/src/configure.in,v
retrieving revision 1.26
diff -u -r1.26 configure.in
--- configure.in 28 Dec 2007 03:43:02 -0000 1.26
+++ configure.in 16 Jan 2008 17:51:30 -0000
@@ -1,6 +1,8 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(d_arithmetic.c)
+AC_CONFIG_HEADER(config.h)
+
AC_SUBST(alsa, yes)
AC_SUBST(jack, no)
AC_SUBST(portaudio, no)
@@ -69,7 +71,7 @@
AC_PROG_GCC_TRADITIONAL
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(gettimeofday select socket strerror)
+AC_CHECK_FUNCS(gettimeofday select socket strerror snprintf)
AC_FUNC_ALLOCA
dnl Checks for libraries.
Also, be sure to run "autoheader" so that config.h.in gets updated to include
the new HAVE_SNPRINTF define.
--
Russell Bryant
More information about the Pd-dev
mailing list