diff --git a/Makefile.am b/Makefile.am index 0f46f6f..eaaf646 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,8 +25,8 @@ libstrophe_la_SOURCES = src/auth.c src/conn.c src/ctx.c \ src/snprintf.c src/sock.c src/stanza.c src/thread.c \ src/tls_openssl.c src/util.c src/rand.c src/uuid.c \ src/common.h src/hash.h src/md5.h src/ostypes.h src/parser.h \ - src/sasl.h src/scram.h src/sha1.h src/sock.h src/thread.h src/tls.h \ - src/util.h src/rand.h + src/sasl.h src/scram.h src/sha1.h src/snprintf.h src/sock.h \ + src/thread.h src/tls.h src/util.h src/rand.h if PARSER_EXPAT libstrophe_la_SOURCES += src/parser_expat.c diff --git a/src/common.h b/src/common.h index 5cbe79a..207734d 100644 --- a/src/common.h +++ b/src/common.h @@ -28,6 +28,7 @@ #include "util.h" #include "parser.h" #include "rand.h" +#include "snprintf.h" /** run-time context **/ @@ -266,8 +267,4 @@ void disconnect_mem_error(xmpp_conn_t * const conn); void auth_handle_open(xmpp_conn_t * const conn); void auth_handle_component_open(xmpp_conn_t * const conn); -/* replacement snprintf and vsnprintf */ -int xmpp_snprintf (char *str, size_t count, const char *fmt, ...); -int xmpp_vsnprintf (char *str, size_t count, const char *fmt, va_list arg); - #endif /* __LIBSTROPHE_COMMON_H__ */ diff --git a/src/snprintf.c b/src/snprintf.c index 03d96f3..e018edb 100644 --- a/src/snprintf.c +++ b/src/snprintf.c @@ -64,49 +64,27 @@ /* JAM: changed declarations to xmpp_snprintf and xmpp_vsnprintf to avoid namespace collision. */ -#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) +#include "snprintf.h" + +/* varargs declarations: */ + +#include +#define VA_LOCAL_DECL va_list ap +#define VA_START(f) va_start(ap, f) +#define VA_END va_end(ap) + +#ifndef HAVE_VSNPRINTF #include #include #include -/* Define this as a fall through, HAVE_STDARG_H is probably already set */ - -#define HAVE_VARARGS_H -#define HAVE_STDARG_H /* JAM: set always */ - - -/* varargs declarations: */ - -#if defined(HAVE_STDARG_H) -# include -# define HAVE_STDARGS /* let's hope that works everywhere (mj) */ -# define VA_LOCAL_DECL va_list ap -# define VA_START(f) va_start(ap, f) -# define VA_SHIFT(v,t) ; /* no-op for ANSI */ -# define VA_END va_end(ap) -#else -# if defined(HAVE_VARARGS_H) -# include -# undef HAVE_STDARGS -# define VA_LOCAL_DECL va_list ap -# define VA_START(f) va_start(ap) /* f is ignored! */ -# define VA_SHIFT(v,t) v = va_arg(ap,t) -# define VA_END va_end(ap) -# else -/*XX ** NO VARARGS ** XX*/ -# endif -#endif - #ifdef HAVE_LONG_DOUBLE #define LDOUBLE long double #else #define LDOUBLE double #endif -int xmpp_snprintf (char *str, size_t count, const char *fmt, ...); -int xmpp_vsnprintf (char *str, size_t count, const char *fmt, va_list arg); - static int dopr (char *buffer, size_t maxlen, const char *format, va_list args); static int fmtstr (char *buffer, size_t *currlen, size_t maxlen, @@ -725,7 +703,6 @@ static int dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c) return 1; } -#ifndef HAVE_VSNPRINTF int xmpp_vsnprintf (char *str, size_t count, const char *fmt, va_list args) { if (str != NULL) @@ -736,28 +713,14 @@ int xmpp_vsnprintf (char *str, size_t count, const char *fmt, va_list args) #ifndef HAVE_SNPRINTF /* VARARGS3 */ -#ifdef HAVE_STDARGS int xmpp_snprintf (char *str,size_t count,const char *fmt,...) -#else -int xmpp_snprintf (va_alist) va_dcl -#endif { -#ifndef HAVE_STDARGS - char *str; - size_t count; - char *fmt; -#endif VA_LOCAL_DECL; int total; VA_START (fmt); - VA_SHIFT (str, char *); - VA_SHIFT (count, size_t ); - VA_SHIFT (fmt, char *); total = xmpp_vsnprintf(str, count, fmt, ap); VA_END; return total; } #endif /* !HAVE_SNPRINTF */ - -#endif /* !HAVE_SNPRINTF */ diff --git a/src/snprintf.h b/src/snprintf.h new file mode 100644 index 0000000..1f005cc --- /dev/null +++ b/src/snprintf.h @@ -0,0 +1,34 @@ +/* + * Copyright Patrick Powell 1995 + * This code is based on code written by Patrick Powell (papowell@astart.com) + * It may be used for any purpose as long as this notice remains intact + * on all source code distributions + */ + +/** @file + * Compatibility wrappers for OSes lacking snprintf(3) and/or vsnprintf(3). + */ + +#ifndef __LIBSTROPHE_SNPRINTF_H__ +#define __LIBSTROPHE_SNPRINTF_H__ + +#include +#include + +#if defined(HAVE_SNPRINTF) || defined(HAVE_VSNPRINTF) +#include +#endif + +#ifdef HAVE_SNPRINTF +#define xmpp_snprintf snprintf +#else +int xmpp_snprintf(char *str, size_t count, const char *fmt, ...); +#endif + +#ifdef HAVE_VSNPRINTF +#define xmpp_vsnprintf vsnprintf +#else +int xmpp_vsnprintf(char *str, size_t count, const char *fmt, va_list arg); +#endif + +#endif /* __LIBSTROPHE_SNPRINTF_H__ */ diff --git a/tests/test_snprintf.c b/tests/test_snprintf.c index b999a2a..c53e00d 100644 --- a/tests/test_snprintf.c +++ b/tests/test_snprintf.c @@ -6,6 +6,7 @@ */ #include +#include /* We don't have separated header file, so include this instead of common.h */ #include "snprintf.c"