Francois Gouget : testbot/testagentd: Add a function to simplify formatting a message.
Module: tools Branch: master Commit: 5179c8ff848da8da501c773a38bd8d9c9d0818ba URL: http://source.winehq.org/git/tools.git/?a=commit;h=5179c8ff848da8da501c773a3... Author: Francois Gouget <fgouget(a)codeweavers.com> Date: Mon Apr 14 15:45:36 2014 +0200 testbot/testagentd: Add a function to simplify formatting a message. --- testbot/src/testagentd/testagentd.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/testbot/src/testagentd/testagentd.c b/testbot/src/testagentd/testagentd.c index 230683a..d5d8dfc 100644 --- a/testbot/src/testagentd/testagentd.c +++ b/testbot/src/testagentd/testagentd.c @@ -129,31 +129,38 @@ const char* status_names[] = {"ok:", "error:", "fatal:"}; /* If true, then the current connection is in a broken state */ static int broken = 0; -/* This is a message which indicates the reason for the status */ -static char* status_msg = NULL; -static unsigned status_size = 0; -static void vset_status_msg(const char* format, va_list valist) + +static char* vformat_msg(char** buf, unsigned* size, const char* format, va_list valist) { - int len; + unsigned len; va_list args; len = 1; do { - if (len >= status_size) + if (len >= *size) { /* len does not count the trailing '\0'. So add 1 and round up * to the next 16 bytes multiple. */ - status_size = (len + 1 + 0xf) & ~0xf; - status_msg = realloc(status_msg, status_size); + *size = (len + 1 + 0xf) & ~0xf; + *buf = realloc(*buf, *size); } va_copy(args, valist); - len = vsnprintf(status_msg, status_size, format, args); + len = vsnprintf(*buf, *size, format, args); va_end(args); if (len < 0) - len = status_size * 1.1; + len = *size * 1.1; } - while (len >= status_size); + while (len >= *size); + return *buf; +} + +/* This is a message which indicates the reason for the status */ +static char* status_msg = NULL; +static unsigned status_size = 0; +static void vset_status_msg(const char* format, va_list valist) +{ + vformat_msg(&status_msg, &status_size, format, valist); if (opt_debug || status != ST_OK) fprintf(stderr, "%s%s: %s\n", status_names[status], rpc_name(rpcid), status_msg); }
participants (1)
-
Alexandre Julliard