From 5dc4cbdf82191bc29afc414ac10204bd17275d69 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 19 Oct 2013 16:58:45 +0200 Subject: util/FormatString: new library to replace g_strdup_printf() --- src/ClientWrite.cxx | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'src/ClientWrite.cxx') diff --git a/src/ClientWrite.cxx b/src/ClientWrite.cxx index ebed5f570..547f72bb5 100644 --- a/src/ClientWrite.cxx +++ b/src/ClientWrite.cxx @@ -19,11 +19,9 @@ #include "config.h" #include "ClientInternal.hxx" - -#include +#include "util/FormatString.hxx" #include -#include /** * Write a block of data to the client. @@ -47,34 +45,9 @@ client_puts(Client *client, const char *s) void client_vprintf(Client *client, const char *fmt, va_list args) { -#ifndef WIN32 - va_list tmp; - int length; - - va_copy(tmp, args); - length = vsnprintf(NULL, 0, fmt, tmp); - va_end(tmp); - - if (length <= 0) - /* wtf.. */ - return; - - char *buffer = (char *)g_malloc(length + 1); - vsnprintf(buffer, length + 1, fmt, args); - client_write(client, buffer, length); - g_free(buffer); -#else - /* On mingw32, snprintf() expects a 64 bit integer instead of - a "long int" for "%li". This is not consistent with our - expectation, so we're using plain sprintf() here, hoping - the static buffer is large enough. Sorry for this hack, - but WIN32 development is so painful, I'm not in the mood to - do it properly now. */ - - static char buffer[4096]; - vsprintf(buffer, fmt, args); - client_write(client, buffer, strlen(buffer)); -#endif + char *p = FormatNewV(fmt, args); + client_write(client, p, strlen(p)); + delete[] p; } void -- cgit v1.2.3