]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Add a wrapper around vstr_add_fmt() to avoid having to link libcharon against libvstr
authorTobias Brunner <tobias@strongswan.org>
Fri, 17 Aug 2012 09:47:52 +0000 (11:47 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 17 Aug 2012 09:47:52 +0000 (11:47 +0200)
At least on Android the latter would be required.

src/libstrongswan/printf_hook.c
src/libstrongswan/printf_hook.h

index 8bd513c0591f8731802d058d7c888b968b73dc8d..6e51aa4c3eb22e36d1e7af486a2822425e5ad5f3 100644 (file)
@@ -237,6 +237,21 @@ static inline Vstr_conf *get_vstr_conf()
        return 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
  */
index b162e6d97b032150dbcd2e3051c756212c600435..7d3f23bceddf2ff241c77940b94e71a65691f9fc 100644 (file)
@@ -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;\
@@ -156,11 +156,25 @@ struct printf_hook_data_t {
        size_t pos;
 };
 
+/**
+ * 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;\
 })