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().
This commit is contained in:
parent
33aec0d673
commit
f73319c048
29
src/client.c
29
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);
|
||||
}
|
||||
|
11
src/client.h
11
src/client.h
@ -20,6 +20,7 @@
|
||||
#define INTERFACE_H
|
||||
|
||||
#include "os_compat.h"
|
||||
#include "gcc.h"
|
||||
|
||||
struct client;
|
||||
|
||||
@ -49,6 +50,16 @@ void client_write(struct client *client, const char *data, size_t length);
|
||||
*/
|
||||
void client_puts(struct client *client, const char *s);
|
||||
|
||||
/**
|
||||
* Write a printf-like formatted string to the client.
|
||||
*/
|
||||
void client_vprintf(struct client *client, const char *fmt, va_list args);
|
||||
|
||||
/**
|
||||
* Write a printf-like formatted string to the client.
|
||||
*/
|
||||
mpd_fprintf void client_printf(struct client *client, const char *fmt, ...);
|
||||
|
||||
int client_print(int fd, const char *buffer, size_t len);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user