util/FormatString: new library to replace g_strdup_printf()
This commit is contained in:
@@ -19,11 +19,9 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "ClientInternal.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
#include "util/FormatString.hxx"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
Reference in New Issue
Block a user