Add new snprintf/vsnprintf implementation. This should fix the compability

problems between Win32 (with its broken implementation) and the standard
stdio API.  Also fixed a bug in debug output where long messages got
truncated to 1023 chars, and in xmpp_stanza_to_text where long stanzas
got truncated by one character.
This commit is contained in:
Jack Moffitt
2006-01-21 00:26:40 +00:00
parent 9a06adc267
commit c52d0aaa28
7 changed files with 875 additions and 35 deletions

View File

@@ -21,10 +21,6 @@
#include "common.h"
#include "util.h"
#ifdef _WIN32
#define vsnprintf _vsnprintf
#endif
/* initialization and shutdown */
void xmpp_initialize(void)
@@ -142,11 +138,26 @@ void xmpp_log(const xmpp_ctx_t * const ctx,
const char * const fmt,
va_list ap)
{
char buf[1024];
int oldret, ret;
char smbuf[1024];
char *buf;
/* FIXME: we don't send log lines > 1024 chars */
vsnprintf(buf, 1023, fmt, ap);
buf = smbuf;
ret = xmpp_vsnprintf(buf, 1023, fmt, ap);
if (ret > 1023) {
buf = (char *)xmpp_alloc(ctx, ret + 1);
if (!buf) {
buf = NULL;
xmpp_error(ctx, "log", "Failed allocating memory for log message.");
return;
}
oldret = ret;
ret = xmpp_vsnprintf(buf, ret, fmt, ap);
if (ret > oldret) {
xmpp_error(ctx, "log", "Unexpected error");
return;
}
}
if (ctx->log->handler)
ctx->log->handler(ctx->log->userdata, level, area, buf);