aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-08-17 11:47:52 +0200
committerTobias Brunner <tobias@strongswan.org>2012-08-17 11:47:52 +0200
commit7ab348370ce072cf7a0af190f596059de0f20246 (patch)
tree785144820f50a7b86bea63c394038731e1229a48
parent21d839204129d64b90c673e3fc93e96b7b9bf33d (diff)
downloadstrongswan-7ab348370ce072cf7a0af190f596059de0f20246.tar.bz2
strongswan-7ab348370ce072cf7a0af190f596059de0f20246.tar.xz
Add a wrapper around vstr_add_fmt() to avoid having to link libcharon against libvstr
At least on Android the latter would be required.
-rw-r--r--src/libstrongswan/printf_hook.c15
-rw-r--r--src/libstrongswan/printf_hook.h18
2 files changed, 31 insertions, 2 deletions
diff --git a/src/libstrongswan/printf_hook.c b/src/libstrongswan/printf_hook.c
index 8bd513c05..6e51aa4c3 100644
--- a/src/libstrongswan/printf_hook.c
+++ b/src/libstrongswan/printf_hook.c
@@ -238,6 +238,21 @@ static inline Vstr_conf *get_vstr_conf()
}
/**
+ * Described in header
+ */
+size_t vstr_print_in_hook(struct Vstr_base *base, size_t pos, const char *fmt,
+ ...)
+{
+ va_list args;
+ int written;
+
+ va_start(args, fmt);
+ written = vstr_add_vfmt(base, pos, fmt, args);
+ va_end(args);
+ return written;
+}
+
+/**
* Wrapper functions for printf and alike
*/
int vstr_wrapper_printf(const char *format, ...)
diff --git a/src/libstrongswan/printf_hook.h b/src/libstrongswan/printf_hook.h
index b162e6d97..7d3f23bce 100644
--- a/src/libstrongswan/printf_hook.h
+++ b/src/libstrongswan/printf_hook.h
@@ -61,7 +61,7 @@ struct printf_hook_data_t {
* Helper macro to be used in printf hook callbacks.
*/
#define print_in_hook(data, fmt, ...) ({\
- int _written = fprintf(data->stream, fmt, ##__VA_ARGS__);\
+ ssize_t _written = fprintf(data->stream, fmt, ##__VA_ARGS__);\
if (_written < 0)\
{\
_written = 0;\
@@ -157,10 +157,24 @@ struct printf_hook_data_t {
};
/**
+ * Wrapper around vstr_add_vfmt(), avoids having to link all users of
+ * print_in_hook() against libvstr.
+ *
+ * @param base Vstr_string to add string to
+ * @param pos position to write to
+ * @param fmt format string
+ * @param ... arguments
+ * @return number of characters written
+ */
+size_t vstr_print_in_hook(struct Vstr_base *base, size_t pos, const char *fmt,
+ ...);
+
+/**
* Helper macro to be used in printf hook callbacks.
*/
#define print_in_hook(data, fmt, ...) ({\
- int _written = vstr_add_fmt(data->base, data->pos, fmt, ##__VA_ARGS__);\
+ size_t _written; \
+ _written = vstr_print_in_hook(data->base, data->pos, fmt, ##__VA_ARGS__);\
data->pos += _written;\
_written;\
})