diff options
author | Max Kellermann <max@duempel.org> | 2008-09-07 13:25:54 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-07 13:25:54 +0200 |
commit | f73319c0489e08e1277b80107729ac1f2ea8e7fd (patch) | |
tree | 1642a21e382fa152092d6019191787a15e14a122 /src/client.c | |
parent | 33aec0d6732a529342e59933b351f4e591d8f8f4 (diff) | |
download | mpd-f73319c0489e08e1277b80107729ac1f2ea8e7fd.tar.gz mpd-f73319c0489e08e1277b80107729ac1f2ea8e7fd.tar.xz mpd-f73319c0489e08e1277b80107729ac1f2ea8e7fd.zip |
client: added client_printf()
Based on client_puts(), client_printf() is the successor of
fdprintf(). As soon as all fdprintf() callers have been rewritten to
use client_printf(), we can remove fdprintf().
Diffstat (limited to 'src/client.c')
-rw-r--r-- | src/client.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c index e9cda12cb..fd0695cc3 100644 --- a/src/client.c +++ b/src/client.c @@ -797,3 +797,32 @@ void client_puts(struct client *client, const char *s) { client_write(client, s, strlen(s)); } + +void client_vprintf(struct client *client, const char *fmt, va_list args) +{ + va_list tmp; + int length; + char *buffer; + + va_copy(tmp, args); + length = vsnprintf(NULL, 0, fmt, tmp); + va_end(tmp); + + if (length <= 0) + /* wtf.. */ + return; + + buffer = xmalloc(length + 1); + vsnprintf(buffer, length + 1, fmt, args); + client_write(client, buffer, length); + free(buffer); +} + +mpd_fprintf void client_printf(struct client *client, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + client_vprintf(client, fmt, args); + va_end(args); +} |