summaryrefslogtreecommitdiff
path: root/src/plugins/weechat-plugin.h
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2011-08-26 09:55:55 +0200
committerSebastien Helleu <flashcode@flashtux.org>2011-08-26 09:55:55 +0200
commitebf72c7eda87e70aed16e890581307f527567bed (patch)
treefa0b2af5ed236bd33afdbe53ebb4efcfc447a590 /src/plugins/weechat-plugin.h
parentc356b16322fc6d70d8e002796984e57dc5a20d8e (diff)
downloadweechat-ebf72c7eda87e70aed16e890581307f527567bed.zip
core: use dynamic buffer size for calls to vsnprintf
Diffstat (limited to 'src/plugins/weechat-plugin.h')
-rw-r--r--src/plugins/weechat-plugin.h30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 2eb8a49a3..5c8837b6c 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -46,7 +46,7 @@ struct timeval;
*/
/* API version (used to check that plugin has same API and can be loaded) */
-#define WEECHAT_PLUGIN_API_VERSION "20110820-01"
+#define WEECHAT_PLUGIN_API_VERSION "20110826-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -145,6 +145,34 @@ struct timeval;
#define WEECHAT_HOOK_SIGNAL_INT "int"
#define WEECHAT_HOOK_SIGNAL_POINTER "pointer"
+/* macro to format string with variable args, using dynamic buffer size */
+#define weechat_va_format(__format) \
+ va_list argptr; \
+ int vaa_size, vaa_num; \
+ char *vbuffer, *vaa_buffer2; \
+ vaa_size = 1024; \
+ vbuffer = malloc (vaa_size); \
+ if (vbuffer) \
+ { \
+ while (1) \
+ { \
+ va_start (argptr, __format); \
+ vaa_num = vsnprintf (vbuffer, vaa_size, __format, argptr); \
+ va_end (argptr); \
+ if ((vaa_num >= 0) && (vaa_num < vaa_size)) \
+ break; \
+ vaa_size = (vaa_num >= 0) ? vaa_num + 1 : vaa_size * 2; \
+ vaa_buffer2 = realloc (vbuffer, vaa_size); \
+ if (!vaa_buffer2) \
+ { \
+ free (vbuffer); \
+ vbuffer = NULL; \
+ break; \
+ } \
+ vbuffer = vaa_buffer2; \
+ } \
+ }
+
struct t_weechat_plugin
{
/* plugin variables */