aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/printf_hook.h
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2012-07-13 11:38:29 +0200
committerMartin Willi <martin@revosec.ch>2012-07-13 13:23:29 +0200
commit1b40b74de032b36c199c4c65016e4736c09b6c81 (patch)
tree69890bf5598be303bdbe721d21eca840434a513e /src/libstrongswan/printf_hook.h
parent549eba30abf99e88a7a197ce80aebf9d91e78e83 (diff)
downloadstrongswan-1b40b74de032b36c199c4c65016e4736c09b6c81.tar.bz2
strongswan-1b40b74de032b36c199c4c65016e4736c09b6c81.tar.xz
Pass opaque data to printf hooks and print_in_hook()
Diffstat (limited to 'src/libstrongswan/printf_hook.h')
-rw-r--r--src/libstrongswan/printf_hook.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/libstrongswan/printf_hook.h b/src/libstrongswan/printf_hook.h
index 8e4a08302..a72295afd 100644
--- a/src/libstrongswan/printf_hook.h
+++ b/src/libstrongswan/printf_hook.h
@@ -24,6 +24,7 @@
typedef struct printf_hook_t printf_hook_t;
typedef struct printf_hook_spec_t printf_hook_spec_t;
+typedef struct printf_hook_data_t printf_hook_data_t;
typedef enum printf_hook_argtype_t printf_hook_argtype_t;
#if !defined(USE_VSTR) && \
@@ -90,13 +91,12 @@ int vstr_wrapper_vasprintf(char **str, const char *format, va_list ap);
/**
* Callback function type for printf hooks.
*
- * @param dst destination buffer
- * @param len length of the buffer
+ * @param data hook data, to pass to print_in_hook()
* @param spec format specifier
* @param args arguments array
* @return number of characters written
*/
-typedef int (*printf_hook_function_t)(char *dst, size_t len,
+typedef int (*printf_hook_function_t)(printf_hook_data_t *data,
printf_hook_spec_t *spec,
const void *const *args);
@@ -104,18 +104,34 @@ typedef int (*printf_hook_function_t)(char *dst, size_t len,
* Helper macro to be used in printf hook callbacks.
* buf and buflen get modified.
*/
-#define print_in_hook(buf, buflen, fmt, ...) ({\
- int _written = snprintf(buf, buflen, fmt, ##__VA_ARGS__);\
- if (_written < 0 || _written >= buflen)\
+#define print_in_hook(data, fmt, ...) ({\
+ int _written = snprintf(data->buf, data->buflen, fmt, ##__VA_ARGS__);\
+ if (_written < 0 || _written >= data->buflen)\
{\
- _written = buflen - 1;\
+ _written = data->buflen - 1;\
}\
- buf += _written;\
- buflen -= _written;\
+ data->buf += _written;\
+ data->buflen -= _written;\
_written;\
})
/**
+ * Data to pass to a printf hook.
+ */
+struct printf_hook_data_t {
+
+ /**
+ * Buffer to write to
+ */
+ char *buf;
+
+ /**
+ * Size of the buffer
+ */
+ size_t buflen;
+};
+
+/**
* Properties of the format specifier
*/
struct printf_hook_spec_t {