aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2012-07-13 12:12:24 +0200
committerMartin Willi <martin@revosec.ch>2012-07-13 13:23:29 +0200
commit060555f082d84a605ecf8e5ab19a7c782eb4b818 (patch)
treebc95d0aa7e535f24cda6925d1671d03571546a04
parent4addc415a5aaa1bac32a0d10587e1eba5dbcc9b7 (diff)
downloadstrongswan-060555f082d84a605ecf8e5ab19a7c782eb4b818.tar.bz2
strongswan-060555f082d84a605ecf8e5ab19a7c782eb4b818.tar.xz
Append directly to base string in vstr printf hooks
-rw-r--r--src/libstrongswan/printf_hook.c13
-rw-r--r--src/libstrongswan/printf_hook.h17
2 files changed, 10 insertions, 20 deletions
diff --git a/src/libstrongswan/printf_hook.c b/src/libstrongswan/printf_hook.c
index 22f5d78d9..2ae804380 100644
--- a/src/libstrongswan/printf_hook.c
+++ b/src/libstrongswan/printf_hook.c
@@ -141,14 +141,13 @@ static int custom_arginfo(const struct printf_info *info, size_t n, int *argtype
*/
static int custom_fmt_cb(Vstr_base *base, size_t pos, Vstr_fmt_spec *fmt_spec)
{
- int i, written;
- char buf[PRINTF_BUF_LEN];
+ int i;
const void *args[ARGS_MAX];
printf_hook_spec_t spec;
printf_hook_handler_t *handler = printf_hooks[SPEC_TO_INDEX(fmt_spec->name[0])];
printf_hook_data_t data = {
- .buf = buf,
- .buflen = sizeof(buf),
+ .base = base,
+ .pos = pos,
};
for (i = 0; i < handler->numargs; i++)
@@ -168,11 +167,7 @@ static int custom_fmt_cb(Vstr_base *base, size_t pos, Vstr_fmt_spec *fmt_spec)
spec.minus = fmt_spec->fmt_minus;
spec.width = fmt_spec->fmt_field_width;
- written = handler->hook(&data, &spec, args);
- if (written > 0)
- {
- vstr_add_buf(base, pos, buf, written);
- }
+ handler->hook(&data, &spec, args);
return 1;
}
diff --git a/src/libstrongswan/printf_hook.h b/src/libstrongswan/printf_hook.h
index fa11b6f9b..93026cc34 100644
--- a/src/libstrongswan/printf_hook.h
+++ b/src/libstrongswan/printf_hook.h
@@ -115,27 +115,22 @@ int vstr_wrapper_vasprintf(char **str, const char *format, va_list ap);
struct printf_hook_data_t {
/**
- * Buffer to write to
+ * Base to append printf to
*/
- char *buf;
+ Vstr_base *base;
/**
- * Size of the buffer
+ * Position in base to write to
*/
- size_t buflen;
+ size_t pos;
};
/**
* Helper macro to be used in printf hook callbacks.
*/
#define print_in_hook(data, fmt, ...) ({\
- int _written = snprintf(data->buf, data->buflen, fmt, ##__VA_ARGS__);\
- if (_written < 0 || _written >= data->buflen)\
- {\
- _written = data->buflen - 1;\
- }\
- data->buf += _written;\
- data->buflen -= _written;\
+ int _written = vstr_add_fmt(data->base, data->pos, fmt, ##__VA_ARGS__);\
+ data->pos += _written;\
_written;\
})