Move declarations of xmpp_{v,}snprintf.
Use HAVE_SNPRINTF and HAVE_VSNPRINTF to conditionnaly use an internal version of these functions or use the libc one.
This commit is contained in:
committed by
Dmitry Podgorny
parent
60cfcc72e6
commit
a61dba0c13
@@ -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/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/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/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/sasl.h src/scram.h src/sha1.h src/snprintf.h src/sock.h \
|
||||||
src/util.h src/rand.h
|
src/thread.h src/tls.h src/util.h src/rand.h
|
||||||
|
|
||||||
if PARSER_EXPAT
|
if PARSER_EXPAT
|
||||||
libstrophe_la_SOURCES += src/parser_expat.c
|
libstrophe_la_SOURCES += src/parser_expat.c
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "rand.h"
|
#include "rand.h"
|
||||||
|
#include "snprintf.h"
|
||||||
|
|
||||||
/** run-time context **/
|
/** 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_open(xmpp_conn_t * const conn);
|
||||||
void auth_handle_component_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__ */
|
#endif /* __LIBSTROPHE_COMMON_H__ */
|
||||||
|
|||||||
@@ -64,49 +64,27 @@
|
|||||||
/* JAM: changed declarations to xmpp_snprintf and xmpp_vsnprintf to
|
/* JAM: changed declarations to xmpp_snprintf and xmpp_vsnprintf to
|
||||||
avoid namespace collision. */
|
avoid namespace collision. */
|
||||||
|
|
||||||
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
|
#include "snprintf.h"
|
||||||
|
|
||||||
|
/* varargs declarations: */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#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 <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
/* 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 <stdarg.h>
|
|
||||||
# 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 <varargs.h>
|
|
||||||
# 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
|
#ifdef HAVE_LONG_DOUBLE
|
||||||
#define LDOUBLE long double
|
#define LDOUBLE long double
|
||||||
#else
|
#else
|
||||||
#define LDOUBLE double
|
#define LDOUBLE double
|
||||||
#endif
|
#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,
|
static int dopr (char *buffer, size_t maxlen, const char *format,
|
||||||
va_list args);
|
va_list args);
|
||||||
static int fmtstr (char *buffer, size_t *currlen, size_t maxlen,
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_VSNPRINTF
|
|
||||||
int xmpp_vsnprintf (char *str, size_t count, const char *fmt, va_list args)
|
int xmpp_vsnprintf (char *str, size_t count, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
if (str != NULL)
|
if (str != NULL)
|
||||||
@@ -736,28 +713,14 @@ int xmpp_vsnprintf (char *str, size_t count, const char *fmt, va_list args)
|
|||||||
|
|
||||||
#ifndef HAVE_SNPRINTF
|
#ifndef HAVE_SNPRINTF
|
||||||
/* VARARGS3 */
|
/* VARARGS3 */
|
||||||
#ifdef HAVE_STDARGS
|
|
||||||
int xmpp_snprintf (char *str,size_t count,const char *fmt,...)
|
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;
|
VA_LOCAL_DECL;
|
||||||
int total;
|
int total;
|
||||||
|
|
||||||
VA_START (fmt);
|
VA_START (fmt);
|
||||||
VA_SHIFT (str, char *);
|
|
||||||
VA_SHIFT (count, size_t );
|
|
||||||
VA_SHIFT (fmt, char *);
|
|
||||||
total = xmpp_vsnprintf(str, count, fmt, ap);
|
total = xmpp_vsnprintf(str, count, fmt, ap);
|
||||||
VA_END;
|
VA_END;
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
#endif /* !HAVE_SNPRINTF */
|
#endif /* !HAVE_SNPRINTF */
|
||||||
|
|
||||||
#endif /* !HAVE_SNPRINTF */
|
|
||||||
|
|||||||
34
src/snprintf.h
Normal file
34
src/snprintf.h
Normal file
@@ -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 <stddef.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#if defined(HAVE_SNPRINTF) || defined(HAVE_VSNPRINTF)
|
||||||
|
#include <stdio.h>
|
||||||
|
#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__ */
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/* We don't have separated header file, so include this instead of common.h */
|
/* We don't have separated header file, so include this instead of common.h */
|
||||||
#include "snprintf.c"
|
#include "snprintf.c"
|
||||||
|
|||||||
Reference in New Issue
Block a user