aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/printf_hook.h
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2012-07-13 11:46:39 +0200
committerMartin Willi <martin@revosec.ch>2012-07-13 13:23:29 +0200
commit4addc415a5aaa1bac32a0d10587e1eba5dbcc9b7 (patch)
treecca4b48d9d0ae8cfa4b1460a805fb3eefc171e1c /src/libstrongswan/printf_hook.h
parent1b40b74de032b36c199c4c65016e4736c09b6c81 (diff)
downloadstrongswan-4addc415a5aaa1bac32a0d10587e1eba5dbcc9b7.tar.bz2
strongswan-4addc415a5aaa1bac32a0d10587e1eba5dbcc9b7.tar.xz
Write directly to FILE stream in glibc printf hooks
Diffstat (limited to 'src/libstrongswan/printf_hook.h')
-rw-r--r--src/libstrongswan/printf_hook.h72
1 files changed, 47 insertions, 25 deletions
diff --git a/src/libstrongswan/printf_hook.h b/src/libstrongswan/printf_hook.h
index a72295afd..fa11b6f9b 100644
--- a/src/libstrongswan/printf_hook.h
+++ b/src/libstrongswan/printf_hook.h
@@ -46,6 +46,29 @@ enum printf_hook_argtype_t {
PRINTF_HOOK_ARGTYPE_POINTER = PA_POINTER,
};
+/**
+ * Data to pass to a printf hook.
+ */
+struct printf_hook_data_t {
+
+ /**
+ * Output FILE stream
+ */
+ FILE *stream;;
+};
+
+/**
+ * Helper macro to be used in printf hook callbacks.
+ */
+#define print_in_hook(data, fmt, ...) ({\
+ int _written = fprintf(data->stream, fmt, ##__VA_ARGS__);\
+ if (_written < 0)\
+ {\
+ _written = 0;\
+ }\
+ _written;\
+})
+
#else
#include <vstr.h>
@@ -86,23 +109,24 @@ int vstr_wrapper_vasprintf(char **str, const char *format, va_list ap);
#define vsnprintf vstr_wrapper_vsnprintf
#define vasprintf vstr_wrapper_vasprintf
-#endif
-
/**
- * Callback function type for printf hooks.
- *
- * @param data hook data, to pass to print_in_hook()
- * @param spec format specifier
- * @param args arguments array
- * @return number of characters written
+ * Data to pass to a printf hook.
*/
-typedef int (*printf_hook_function_t)(printf_hook_data_t *data,
- printf_hook_spec_t *spec,
- const void *const *args);
+struct printf_hook_data_t {
+
+ /**
+ * Buffer to write to
+ */
+ char *buf;
+
+ /**
+ * Size of the buffer
+ */
+ size_t buflen;
+};
/**
* Helper macro to be used in printf hook callbacks.
- * buf and buflen get modified.
*/
#define print_in_hook(data, fmt, ...) ({\
int _written = snprintf(data->buf, data->buflen, fmt, ##__VA_ARGS__);\
@@ -115,21 +139,19 @@ typedef int (*printf_hook_function_t)(printf_hook_data_t *data,
_written;\
})
+#endif
+
/**
- * Data to pass to a printf hook.
+ * Callback function type for printf hooks.
+ *
+ * @param data hook data, to pass to print_in_hook()
+ * @param spec format specifier
+ * @param args arguments array
+ * @return number of characters written
*/
-struct printf_hook_data_t {
-
- /**
- * Buffer to write to
- */
- char *buf;
-
- /**
- * Size of the buffer
- */
- size_t buflen;
-};
+typedef int (*printf_hook_function_t)(printf_hook_data_t *data,
+ printf_hook_spec_t *spec,
+ const void *const *args);
/**
* Properties of the format specifier